这是我的log4j.properties
# Define the root logger with appender file
log4j.rootLogger = DEBUG,FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=/media/.I have given the whole path../MyProject/log.log
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d{MM-dd@HH:mm:ss} %-5p (%13F:%L) %3x - %m%n
这是我的java文件
package examples;
import java.util.logging.Logger;
import org.apache.log4j.PropertyConfigurator;
public class Test {
static Logger logger = Logger.getLogger(Test.class.getName());
public static void main(String a[]){
//PropertiesConfigurator is used to configure logger from properties file
PropertyConfigurator.configure("log4j.properties");
//Log in console in and log file
//logger.debug("Log4j appender configuration is successful !!");
logger.info("Log4j appender configuration is successful !!");
}
}
我仍然在控制台上获取输出消息,只有我的log.log文件为空。 我有权限写入该文件 我在日食中运行这是一个问题。
答案 0 :(得分:1)
使用log4j包中的Logger。
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
像这样创建你的记录器:
static final Logger logger = LogManager.getLogger(Test.class.getName());
log4j没有捕获java.util.logging日志消息。