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
!
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?