Ankit

-----Original Message-----
From: Ankit Agarwal [mailto:ankit_agarwal@...] 
Sent: Monday, April 10, 2017 3:24 PM
To: users@tomcat.apache.org
Subject: Using Log4J2 2.8 (via the 1.2 API Bridge) for Tomcat8 Internal Logging 
- RollingFileAppender does not (cannot?) create new Log File

> Hi,
>
> I’m using Log4J2 (2.8) via the 1.2 API Bridge for Tomcat 8 internal logging.
>
> I followed the instructions here:
> https://tomcat.apache.org/tomcat-8.0-doc/logging.html#Using_Log4j
> <https://tomcat.apache.org/tomcat-8.0-doc/logging.html#Using_Log4j>
> - With the exception that I also copied the Bridge JAR into the Tomcat8 lib 
> directory
>
> I have configured Log4J2 with this XML file
>
> <?xml version="1.0" encoding="utf-8"?>
> <Configuration status="info">
>      <Properties>
>           <Property name="logDirectory">${sys:catalina.base}/logs</Property>
>           <Property name="systemName">CMS</Property>
>           <Property name="componentName">Tomcat</Property>
>           <Property name="serverIpAddress">${env:PUBLIC_IP_ADDRESS}</Property>
>           <!-- <Property name="layout">%d [%t] %-5p %c- %m%n</Property> -->
>           <Property name="layout">%d{DATE} "%d{ISO8601}" "${systemName}" 
> "${componentName}" "%X{clientIpAddress}" "%X{clientTcpPort}" "%X{username}" 
> "%X{sessionId}" "%X{sessionAuthenticationId}" 
> "%X{sessionAuthenticationToken}" "${serverIpAddress}" "%T" "%t" "%X{apiName}" 
> "%X{apiSystemActionType}" "%X{apiSystemItemType}" "%x" "%l" "%p" 
> "%m"%n%n</Property>
>      </Properties>
>      <Appenders>
>           <Console name="CONSOLE" target="SYSTEM_OUT">
>                <PatternLayout pattern="${layout}"/>
>           </Console>
>           <RollingFile name="CATALINA" 
> fileName="${logDirectory}/catalina.log" 
> filePattern="${logDirectory}/catalina-%i.log.gz">
>                <PatternLayout pattern="${layout}"/>
>                <Policies>
>                     <SizeBasedTriggeringPolicy size=“100 MB" />
>                </Policies>
>                <DefaultRolloverStrategy max="20" />
>           </RollingFile>
>           <RollingFile name="LOCALHOST" 
> fileName="${logDirectory}/localhost.log" 
> filePattern="${logDirectory}/localhost-%i.log.gz">
>                <PatternLayout pattern="${layout}"/>
>                <Policies>
>                     <SizeBasedTriggeringPolicy size="100 MB"/>
>                </Policies>
>                <DefaultRolloverStrategy max="20" />
>           </RollingFile>
>           <RollingFile name="MANAGER" fileName="${logDirectory}/manager.log" 
> filePattern="${logDirectory}/manager-%i.log.gz">
>                <PatternLayout pattern="${layout}"/>
>                <Policies>
>                     <SizeBasedTriggeringPolicy size="100 MB"/>
>                </Policies>
>                <DefaultRolloverStrategy max="20" />
>           </RollingFile>
>           <RollingFile name="HOST-MANAGER" 
> fileName="${logDirectory}/host-manager.log" 
> filePattern="${logDirectory}/host-manager-%i.log.gz">
>                <PatternLayout pattern="${layout}"/>
>                <Policies>
>                     <SizeBasedTriggeringPolicy size="100 MB"/>
>                </Policies>
>                <DefaultRolloverStrategy max="20" />
>           </RollingFile>
>      </Appenders>
>      <Loggers>
>           <Root level="info">
>                <AppenderRef ref="CATALINA"/>
>           </Root>
>           <Logger 
> name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost]" 
> level="info" additivity="false">
>                <AppenderRef ref="LOCALHOST"/>
>           </Logger>
>           <Logger 
> name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager]"
>  level="info" additivity="false">
>                <AppenderRef ref="MANAGER"/>
>           </Logger>
>           <Logger 
> name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager]"
>  level="info" additivity="false">
>                <AppenderRef ref="HOST-MANAGER"/>
>           </Logger>
>      </Loggers>
> </Configuration>
>
> All 4 RollingFile Appenders are configured identically (except for
> the log filename).
>
> The problem I’m running into is that when the
> SizeBasedTriggeringPolicy is executed, the current log file is
> zipped. However, a new log file is not created.
>
> As a result, the Tomcat8 stops logging.
>
> If I restart Tomcat8, then a new file is created and the Tomcat8
> functions normally, but only until this new log file reaches its
> limit and is zipped up. Then once again, the problem repeats itself.
>
> Does the 1.2 API Bridge / Tomcat 8 not support the
> SizeBasedTriggeringPolicy?
>
> Do I have any options other than restarting the Tomcat8? Will the
> TimeBasedTriggeringPolicy work and is that my only option?
>
> Since the Log4J2 being used in Tomcat8 has no problem creating the
> required files on restart, I don’t think its a permissions issue.
>
> I’d appreciate any thoughts and pointers.
>
> Thanks,
> Ankit

3 things:

1. Sorry, I cannot answer your questions directly cuz I'm kind of newbie in 
this arena.

2. Are you allowed to overwrite what log files that Tomcat would generate 
anyway?  We use Log4J2 to create custom log files and leave the 
Tomcat-generated ones alone.  Maybe our configuration is a little wacky.  :-)

3. In my (very limited) experience, Log4J2 creates a new log file only when the 
first log-able event actually happens.  IOW, it won't create an empty log file 
without actually having something to log.

Please let us know what you learn and how you progress in solving the issue!

--
Cris Berneburg
CACI Lead Software Engineer


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to