解决 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" 解决办法
经常看到这样的warning,今天研究了一下,终于大概搞明白了。
设置log4j配置的路径,需要指定下面的JVM参数:
-Dlog4j.configuration=file:/C:/workspace/COM_tests/log4j.properties
or
-Dlog4j.configuration=file:/C:/workspace/COM_tests/log4j.xml
或者在代码中指定:
System.setProperty("log4j.configuration", "file:/C:/workspace/COM_tests/log4j.properties");
读取这个配置的source code在org.apache.log4j.LogManager类。
log4j:WARN No appenders could be found for logger (se.ericsson.jcat.com.cli.testsuites.TestSuiteComCli).
log4j:WARN Please initialize the log4j system properly.
如果我们需要解决上面的warning,
1. 检查log4j.properties or log4j.xml是否被load成功了(如上所述);
2. 检查log4j.properties中有没有定义相应的logger。比如上面的问题需要定义如下:
log4j.logger.se.ericsson.jcat.com.cli.testsuites.TestSuiteComCli=DEBUG, Console
其中Console是appender.
log4j.appender.Console=org.apache.log4j.ConsoleAppender
"log4j:WARN No appenders could be found for logger" 解决办法
经常看到这样的warning,今天研究了一下,终于大概搞明白了。
设置log4j配置的路径,需要指定下面的JVM参数:
-Dlog4j.configuration=file:/C:/workspace/COM_tests/log4j.properties
or
-Dlog4j.configuration=file:/C:/workspace/COM_tests/log4j.xml
或者在代码中指定:
System.setProperty("log4j.configuration", "file:/C:/workspace/COM_tests/log4j.properties");
读取这个配置的source code在org.apache.log4j.LogManager类。
log4j:WARN No appenders could be found for logger (se.ericsson.jcat.com.cli.testsuites.TestSuiteComCli).
log4j:WARN Please initialize the log4j system properly.
如果我们需要解决上面的warning,
1. 检查log4j.properties or log4j.xml是否被load成功了(如上所述);
2. 检查log4j.properties中有没有定义相应的logger。比如上面的问题需要定义如下:
log4j.logger.se.ericsson.jcat.com.cli.testsuites.TestSuiteComCli=DEBUG, Console
其中Console是appender.
log4j.appender.Console=org.apache.log4j.ConsoleAppender