如何正确初始化log4j系统

时间:2015-05-15 11:10:01

标签: java log4j

我收到两个警告。

log4j:WARN No appenders could be found for logger (com.org.Resolver).
log4j:WARN Please initialize the log4j system properly.

如何解决?

我的java类名称 Resolver.java

在java类中我正在调用

private static Log log = LogFactory.getLog(Resolver.class);

1 个答案:

答案 0 :(得分:0)

您需要将log4j.properties或log4j.xml放在类路径中。因此,创建文件名log4j.properties并用以下内容替换内容:

# Root logger option
log4j.rootLogger=INFO, DEBUG, stdout, file

# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
#. represents the current folder (usually the project root folder)        
log4j.appender.file.File=./logging.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n