更新- 这个问题是我自己做的。
在某个阶段,这个特定的测试类进行了测试以确保记录某些内容。在设置中,我之前删除了所有附加程序并添加了我自己的附加程序以进行测试时断言。该测试早已不复存在,但该金块仍保留在设置中:Logger.getRootLogger().removeAllAppenders();
.
很抱歉误报。:)
在 IDEA 我有以下测试:
@Test
public void shouldLog() {
URL resource = Thread.currentThread().getContextClassLoader()
.getResource("log4j.properties");
System.out.println("resource = " + resource);
final Logger logger = Logger.getLogger(getClass());
logger.info("Hello world");
}
它因此输出:
"C:\Program Files\Java\jdk1.5.0_18\bin\java" -classpath "C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 11.1\lib\idea_rt.jar" -ea -Dfile.encoding=UTF-8 com.intellij.rt.execution.CommandLineWrapper C:\DOCUME~1\JMAWSO~1.NT3\LOCALS~1\Temp\classpath2294205410661538428.tmp @vm_params C:\DOCUME~1\JMAWSO~1.NT3\LOCALS~1\Temp\vm_params5645362020129462784.tmp com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 au.com.gmm.repo.RepoThreadCleanupServiceTest,shouldLog
resource = file:/C:/user/jem/projects/GMM/out/test/cashflow/log4j.properties
log4j:WARN No appenders could be found for logger (au.com.gmm.repo.RepoThreadCleanupServiceTest).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Process finished with exit code 0
这是一个著名的问题,许多新手一遍又一遍地看到。今天被它难住了,我觉得有点傻。
http://logging.apache.org/log4j/1.2/faq.html#noconfig说log4j uses Thread.getContextClassLoader().getResource() to locate the default configuration files
。但是,我的测试检查 Thread.currentThread().getContextClassLoader().getResource("log4j.properties")
并找到没有问题的属性文件。
该文件的内容是:
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{HH:mm:ss.SSS} %c - %m%n