log4j.properties文件 - 警告在eclipse中找不到日志记录器的appender

时间:2013-11-27 15:36:28

标签: java logging log4j

我尝试使用`log4j.properties'文件配置log4j。

所有的工作,但我发现了一些奇怪的警告:

  

log4j:WARN找不到logger(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)的appender。   log4j:WARN请正确初始化log4j系统。   log4j:WARN有关详细信息,请参阅http://logging.apache.org/log4j/1.2/faq.html#noconfig

我无法弄清楚这有什么问题。一切都应该有效。

log4j.properties 的内容:

# Root logger option
log4j.rootLogger=warn, stdout, file 

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.target=System.out 
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.conversionPattern=%d{ABSOLUTE} %5p %t %c{1}:%M:%L - %m%n 

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.file=logs/oms_test.log
log4j.appender.file.MaxFileSize=2MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.conversionPattern=%d{ABSOLUTE} %5p %t %c{1}:%M:%L - %m%n 

log4j.appender.debugfile=org.apache.log4j.RollingFileAppender
log4j.appender.debugfile.file=logs/oms_test-debug.log
log4j.appender.debugfile.layout=org.apache.log4j.PatternLayout
log4j.appender.debugfile.layout.conversionPattern=%d{ABSOLUTE} %5p %t %c{1}:%M:%L - %m%n 
log4j.logger.com.softserve.edu=DEBUG, debugfile
log4j.logger.com.my.app.somepackage.subpackage.ClassName=INFO

这是项目的打击:

project struckture

修改

我从代码加载log4j.properties:

PropertyConfigurator.configure("src/resourses/log4j.properties");
Logger.getRootLogger();

EDIT2:

我尝试将位置log4j.properties更改为src/main/resoursessrc/test/resoursessrc/resourses,并更改了代码加载。

总是失败:

log4j:ERROR Could not read configuration file [log4j.properties].
java.io.FileNotFoundException: log4j.properties (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    at java.io.FileInputStream.<init>(FileInputStream.java:97)
    at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:372)
    at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:403)
    at com.softserve.edu.SearchingOrdersPageTest.setUp(SearchingOrdersPageTest.java:31)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
log4j:ERROR Ignoring configuration file [log4j.properties].
  • 如何解决这个问题?

4 个答案:

答案 0 :(得分:4)

log4j.properties放到bin(类路径)可以解决您的问题。

答案 1 :(得分:4)

我遇到了同样的问题,当我将log4j.xml放入WEB-INF / classes时,我已经解决了这个问题

查看此信息并回答initialize log4j

答案 2 :(得分:0)

你把log4j.properties放在哪里确保你使用propertyconfigurator调用它,如下所示

     PropertyConfigurator.configure("D:\\logs\\log4j.properties");    

     final Logger  LOGGER = Logger.getRootLogger();
     LOGGER.info("sddd");
     LOGGER.debug("ffff");**

答案 3 :(得分:-1)

只需粘贴以下代码即可。

System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger");
System.setProperty("webdriver.chrome.driver","C:\\Users\\gwda\\Desktop\\chromedriver.exe"); 
WebDriver s1 = new ChromeDriver();

这可以解决您的麻烦。