15 No appenders could be found for logger Please initialize the log4j system properly

Log4j Debug记录

log4j:WARN No appenders could be found for logger

错误提示信息

1
2
3
log4j:WARN No appenders could be found for logger (demo.Log4jExample).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

配置文件内容

/Log4jDemo/src/log4j.properties
1
2
3
4
5
6
7
8
9
10
11
# 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=htmlLayout.html

# Define the layout for file appender
Log4j.appender.FILE.layout=org.apache.Log4j.HTMLLayout
Log4j.appender.FILE.layout.Title=HTML Layout Example
Log4j.appender.FILE.layout.LocationInfo=true

解决方案

配置文件写错了,包名应该小写开头,将上述的Log4j改成log4j:

# 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=htmlLayout.html

# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.HTMLLayout
log4j.appender.FILE.layout.Title=HTML Layout Example
log4j.appender.FILE.layout.LocationInfo=true