我的春季版本是4.2.5,(org.springframework.web.util.Log4jConfigListener)已被放弃。 Spring4.x是否必须使用Log4j2.xml?
这是我的代码。 我不知道哪里出了问题?
的log4j.xml
/src/main/resources/log4j.xml
的web.xml
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>webapp.root</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.WebAppRootListener</listener-class>
</listener>
的log4j.xml
<appender name="MANAGER-APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${webapp.root}/resources/logs/manager.log" />
<param name="Append" value="true" />
<param name="encoding" value="UTF-8" />
<param name="DatePattern" value="'.'yyyy-MM-dd'.log'" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%-5p] [%d{yyy/MM/dd HH:mm:ss} %c{2}] - %m%n" />
</layout>
</appender>
日志文件
ERR [err] log4j:ERROR setFile(null,true) call failed.
ERR [err] java.io.FileNotFoundException: /resources/logs/manager.log (No such file or directory)
ERR [err] at java.io.FileOutputStream.open0(Native Method)
ERR [err] at java.io.FileOutputStream.<init>(Unknown Source)
ERR [err] at java.io.FileOutputStream.<init>(Unknown Source)
ERR [err] at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:165)
ERR [err] at org.apache.log4j.DailyRollingFileAppender.activateOptions(DailyRollingFileAppender.java:223)
ERR [err] at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:307)
ERR [err] at org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:295)
ERR [err] at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:191)
ERR [err] at org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:523)
ERR [err] at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:872)
ERR [err] at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:778)
ERR [err] at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:526)
ERR [err] at org.apache.log4j.LogManager.<clinit>(LogManager.java:127)
ERR [err] at org.apache.log4j.Logger.getLogger(Logger.java:104)
ERR [err] at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:262)
ERR [err] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
ERR [err] at org.apache.commons.logging.impl.LogFactoryImpl.createLogFromClass(LogFactoryImpl.java:1025)
ERR [err] at [internal classes]
ERR [err] at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:302)
ERR [err] at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
ERR [err] at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:2420)
ERR [err] at [internal classes]
ERR [err] at com.ibm.ws.webcontainer.osgi.WebContainer.access$000(WebContainer.java:104)
ERR [err] at com.ibm.ws.webcontainer.osgi.WebContainer$2.run(WebContainer.java:870)
ERR [err] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
ERR [err] at java.util.concurrent.FutureTask.run(Unknown Source)
ERR [err] at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
ERR [err] at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
ERR [err] at java.lang.Thread.run(Unknown Source)
ERR [err] log4j:ERROR Either File or DatePattern options are not set for appender [MANAGER-APPENDER].
感谢您花时间去寻找,任何帮助都很棒。
答案 0 :(得分:0)
正如它所说/resources/logs/manager.log(没有这样的文件或目录)。
我认为最可能的原因是您运行该程序的用户没有/ resources / logs的权限,因此log4j无法创建该文件。