0

My current application is on Spring 3.2 / Log4J2 2.3 / Websphere 8.5 with JDK6, I have to stick to older version of Log4J2 because the application has to stay with JDK6.

Now there is an interesting issue, seems caused by configuration or a bug in Log4J2, is that each time when I restart the application from server, then the RollingFile is working in a crazy mode, each new log file roll over grows in the size of the same size defined in SizeBasedTriggeringPolicy. Following is Log4J2.xml configuration:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
    <Properties>
        <Property name="log-path">C:/Application/logs</Property>
    </Properties>
    <Appenders>
        <Console name="STDOUT">
            <PatternLayout>
                <pattern>%p -- %c -- %m%n</pattern>
            </PatternLayout>
        </Console>
        <RollingFile name="RollingFile" fileName="${log-path}/application-l4j-haha.log"
            filePattern="${log-path}/application-l4j-haha-%i.log">
            <PatternLayout>
                <pattern>%p -- %c -- %m%n</pattern>
            </PatternLayout>
            <Policies>
                <SizeBasedTriggeringPolicy size="2 MB" />
            </Policies>
            <DefaultRolloverStrategy max="5" />
        </RollingFile>
    </Appenders>
    <Loggers>
        <Logger name="root" level="debug" additivity="false">
            <AppenderRef  ref="RollingFile" level="debug" />
        </Logger>
        <Root level="debug" additivity="false">
            <AppenderRef  ref="RollingFile" />
        </Root>
    </Loggers>
</Configuration>

So the each file should maintain in 2Mb and rotated in 5 files

Here is the file output, it is apparent that the log file grows on each roll over and reach to a very big size, and each new file is bigger than previous one in exact 2Mb !

enter image description here

Also it is interestingly only happen when I RESTART the application. If I remove all the log files and let Log4J2 start from scratch then the log file roll over as expected, all files in the same size. However if I stop the application from server and start again then the log file goes all crazy again.

Also this issue is found not only in Websphere but also Tomcat, so I guess it is not a server issue.

Is there any known bug related to this issue and how to fix it?

Dreamer
  • 7,333
  • 24
  • 99
  • 179
  • In tomcat the file is always open and file truncation does not work (under linux anyway) - a better solution is to use logroate with copytruncate - see https://stackoverflow.com/questions/18887682/tomcat-catalina-out-logrotate-on-redhat-not-working-properly – Scary Wombat Aug 15 '17 at 01:55
  • @Scary Wombat thanks but I think it is not an server issue? The log is generated by Log4J but not throw server logging. And the issue happened almost to all server I have tried. – Dreamer Aug 15 '17 at 01:59
  • I am not understanding your comment at all – Scary Wombat Aug 15 '17 at 02:02
  • my bad, it should be "The log is generated by Log4J but not `through` server logging". The issue happened in both Websphere and Tomcat. Also what do you mean by `in tomcat the file is always open`? – Dreamer Aug 15 '17 at 02:08
  • Sorry I am confusing myself as well ;-) Of course you are talking about application logging but I am confusedly talking about `catalina.out` - Sorry – Scary Wombat Aug 15 '17 at 02:11
  • @Scary Wombat ah I see. Thanks anyway :) – Dreamer Aug 15 '17 at 02:17

1 Answers1

0

Updating the log4j version to 2.11.0 resolves this issue.

4b0
  • 21,981
  • 30
  • 95
  • 142