【发布时间】:2014-03-25 22:18:13
【问题描述】:
在将我的应用程序转换为网络应用程序之前。 Log4j 将日志记录在我在 log4j2.xml 中定义的正确日志文件(info.log 和 debug.log)中。
但是,当我将应用程序更改为 web.app 时,所有日志现在都记录到 servlet 容器 (tomcat 7) 中的 catalina.out 文件中。 部署应用程序 log4j2 后会创建这些日志文件,但它们仍然为空,所有日志都转到 catalina.out 文件。
你能建议我做错了什么吗?
在web.xml中,我添加了必要的配置。
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>project-service</display-name>
<!-- Support for Spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>log4j2.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
</web-app>
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace" strict="true" name="XMLConfigTest"
packages="">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<RollingRandomAccessFile name="RollingRandomAccessFileDebug" fileName="/local/deploy/logs/debug.log"
filePattern="logs/$${date:yyyy-MM}/project-%d{MM-dd-yyyy}-%i.log.gz"
immediateFlush="false"
append="false">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="250 MB"/>
</Policies>
</RollingRandomAccessFile>
<RollingRandomAccessFile name="RollingRandomAccessFile" fileName="/local/deploy/logs/info.log"
filePattern="logs/$${date:yyyy-MM}/project-%d{MM-dd-yyyy}-%i.log.gz"
immediateFlush="false"
append="false">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="250 MB"/>
</Policies>
</RollingRandomAccessFile>
<!--<Async name="AsyncConsole">-->
<!--<AppenderRef ref="Console"/>-->
<!--</Async>-->
</Appenders>
<Loggers>
<Root level="TRACE">
<AppenderRef ref="RollingRandomAccessFileDebug" level="DEBUG"/>
<AppenderRef ref="RollingRandomAccessFile" level="INFO"/>
<AppenderRef ref="Console" level="TRACE"/>
</Root>
</Loggers>
</Configuration>
【问题讨论】:
标签: java log4j tomcat7 classpath web.xml