解决log4j:WARN No appenders could be found for logger

##在进项Junit测试时 报出这样的错误的解决方法
##log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).
##log4j:WARN Please initialize the log4j system properly.
##log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

如果想输出某个测试下的Log4j配置文件是这样
log4j.logger.包名=debug,console

#控制台附加器

log4j.logger.opzpy123=debug,console

#控制台附加器
log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.Target = System.out
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern= [%-5p][%d{
     yyyy-MM-dd HH:mm:ss}]%m%n

此时会报错
log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

是因为没有指定rootLogger报出的错误
在首行添加

log4j.rootLogger=error

之后就Ok

log4j.rootLogger=error
log4j.rootLogger=error
log4j.rootLogger=error
log4j.rootLogger=error

你可能感兴趣的:(java测试日志输出,log4j红字警告,junit测试)