Tomcat 7 writes all the logs to the catalina.out file, but not to specific log4j2 files

Before you convert my application to a web application. Log4j was writing logs to the correct log files (info.log and debug.log), which I defined in log4j2.xml .

But when I changed my application to web.app, all the logs are now written to the catalina.out file in the servlet container ( tomcat 7 ). After the application is deployed, log4j2 creates this log file, but they remain empty and all the logs go to the catalina.out file.

Could you suggest what I am doing wrong.

In web.xml, I added the necessary configuration.

<?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> 
+7
java classpath tomcat7 log4j
source share
1 answer

change fileName attribute from

filename = "/local/expand/logs/info.log"

to something like that (regardless of the way in case of cheers)

FileName = "$ {SYS: catalina.home} /logs/info.log"

if it is written to both the katalin and the log file, then link to this link

http://app-inf.blogspot.com/2012/10/java-util-logging-behaviour-in-tomcat.html

+5
source share

All Articles