简体   繁体   中英

logging with log4j2 in java web apps

I'm trying to use log4j2 with java web applications. I've configured the log4j2.xml so that it rolls over (based on size) and it worked perfectly. but when I reload the web app it doesn't continue the normal behaviour, instead it is like it never sees the old files and just start appending to the old ones.

It seems the configuration for web apps is different the standalone apps. I went to their site but I couldn't get understand what they say for web apps. So, is there a tutorial (other than the javabeat with spring) that I can learn from. or can I go with the normal logging as the standalone but add some modifications.

Note: I'm modifying a code that is already on site (for a company) and the way the apps are designed , unfortunately, is that each web app has its own log4j libs and config.

here is my log4j2.xml config file:

<?xml version="1.0" encoding="UTF-8"?> 
<Configuration> 
  <Appenders>
    <RollingFile name="FileLogger" fileName="C:/Path/l-${date:yyyy-MM-dd}.log" filePattern="C:/Path/l-%d{yyyy-MM-dd}--%i.log" append="true">` 
      <PatternLayout pattern="%d{dd MMM yyyy HH:mm:ss.SSS} [%t] %-5level %logger - %msg%n"/> 
      <Policies>
                <SizeBasedTriggeringPolicy size="1 KB"/>
      </Policies>
      <DefaultRolloverStrategy fileIndex="min" max="3"/>
    </RollingFile>  
    <Console name="STDOUT" target="SYSTEM_OUT"> 
      <PatternLayout pattern="%d{dd MMM yyyy HH:mm:ss.SSS} [%t] %-5level %logger - %msg%n"/> 
    </Console> 
  </Appenders> 
  <Loggers> 
    <Logger name="Test" level="info"/> 
    <Root level="trace"> 
      <AppenderRef ref="FileLogger"/> 
      <AppenderRef ref="STDOUT"/> 
    </Root> 
  </Loggers> 
</Configuration>

To be honest, I'm not sure if what you describe is a bug or a missing feature. May I suggest that you raise a feature request for this on the log4j2 Jira issue tracker?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM