log4j:WARN No appenders could be found for logger

【log4j:WARN No appenders could be found for logger】曾无好事来相访,赖尔高文一起予。这篇文章主要讲述log4j:WARN No appenders could be found for logger相关的知识,希望能为你提供帮助。
Eclipse 用Spring导入

log4j:WARN No appenders could be found for logger

文章图片
这几个文件都正常,可是写简单的代码输出HelloWorld,运行就出现下面的错误:
log4j:WARN No appenders could be found for logger

文章图片

解决这问题是在src下新建log4j.properties文件
log4j:WARN No appenders could be found for logger

文章图片

在这文件写入下面代码:
log4j.rootLogger=DEBUG, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %10l - %m%n
##log4j.appender.FILE=org.apache.log4j.RollingFileAppender
##log4j.appender.FILE.File=E:/logs/log4j.log
##log4j.appender.FILE.MaxFileSize=1MB
##log4j.appender.FILE.Append = true
##log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
##log4j.appender.FILE.layout.ConversionPattern=%d{yyyy/MM/dd/HH:mm:ss} %-5p [%t] %10l - %m%n
log4j:WARN No appenders could be found for logger

文章图片

这样就OK了。

    推荐阅读