Reputation: 1
We are using log4j2 on Window 7 Enterprise. JBoss Developer Studio 8(this really doesn't matter)
RollingFileAppender rolls over the log files properly, however the original log file keep old logs and continues to increase in size. There is a JIRA bug (LOG4J2-904) related to this . I followed some of the options like
Some comments indicated problem fixed as of log4j 2.4.1 version. However, I am still seeing the same problem in log4j 2.5.
I tried logging to both RollingFile and RollingRandomAccessFile appenders at the same time. An image of the log folder in included Here is the image of Log folder from rollover
Here is my log4j2.xml
<Configuration>
<Properties>
<property name="appname">myapp</property>
<Property name="log-path">${server.dir}/myapp</Property>
</Properties>
<Appenders>
<RollingFile name="DATED_ROLLING_FILE" fileName="${log-path}/${myapp}.log" filePattern="${log-path}/${myapp}_%d{MM-dd-yyyy}-%i.log" maxFileSize="40 KB">
<PatternLayout>
<Pattern>%d: %-5p [%c{1}]:%L - %M %m%n</Pattern>
</PatternLayout>
<Policies>
<OnStartupTriggeringPolicy />
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="40 KB" />
</Policies>
<DefaultRolloverStrategy fileIndex="min" max="100" />
</RollingFile>
<RollingRandomAccessFile name="DATED_RAC_APPENDER" fileName="${log-path}/epermitsrac.log"
filePattern="${log-path}/epermitsrac_%d{MM-dd-yyyy}-%i.log" >
<PatternLayout>
<Pattern>%d: %-5p [%c{1}]:%L - %M %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="40 KB" />
</Policies>
<DefaultRolloverStrategy fileIndex="min" max="100" />
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="DATED_ROLLING_FILE" />
<AppenderRef ref="DATED_RAC_APPENDER" />
</Root>
</Loggers>
</Configuration>
Here is the image of Log folder from rollover. As you can see it does not clear the original File.
Did anyone else experienced same problem and is there a fix for this.
Upvotes: 0
Views: 996
Reputation: 1
I have tried with below configuration and it is working fine, except that the latest file will be with out date.
rootLogger.level = all
appenders = rolling, console
status = warn
appender.console.type = Console
appender.console.name = console
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d [%-5p] (%F:%M:%L) %m%n
# Rolling file based on date for day wise
appender.rolling.type = RollingFile
appender.rolling.name = rolling
#if i use below file name the rollover will not happenning as expected
#appender.rolling.fileName = E:/LOGS/${date:yyyyMMdd}_test.log
#with below filename name the rollover will happen as expected
appender.rolling.fileName = E:/LOGS/test.log
appender.rolling.filePattern = E:/LOGS/%d{yyyyMMdd}_test.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d [%-5p] [%F:%M:%L] %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
#use below for day wise roll over
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
rootLogger.appenderRefs = rolling, console
rootLogger.appenderRef.console.ref = console
rootLogger.appenderRef.rolling.ref = rolling
rootLogger.appenderRef.stdout.ref = console, rolling
Upvotes: 0