当前位置: 首页 > 知识库问答 >
问题:

log4j.properties文件-WARN在eclipse上找不到logger的附加文件[duplicate]

鲁宏爽
2023-03-14

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

所有的工作,但我得到了一个奇怪的警告:

log4j:警告找不到记录器(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)的附加程序。log4j:警告请正确初始化log4j系统。log4j:警告有关更多信息,请参见http://logging.apache.org/log4j/1.2/faq.html#noconfig。

# 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

我从代码加载log4j.properties:

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

编辑2:

我尝试将不同位置的位置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].
    null

共有1个答案

谭灿
2023-03-14

我也遇到了同样的问题,当我将log4j.xml放入WEB-INF/classs中时就解决了这个问题

检查此帖子并回答initialize log4j。

 类似资料: