Reputation: 346
I have just started using log4j2 with slf4j2 but I'm facing a problem where I'm trying to create rolling log files on daily basis. I am able to create an active log file but when I change the system date by one day, logging happens on the same active file which I thought it should have archived previous days' logs to another file.
Following is the log4j2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="ERROR" monitorInterval="5">
<Properties>
<Property name="log-path">${sys:catalina.base}/logs</Property>
</Properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout
pattern="%d{dd-MMM-YYYY HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<RollingFile name="file-gen" fileName="${log-path}/demopro.log"
filePattern="${log-path}/%d{yyyy-MM}/demopro-%d{dd-MM-yyyy}.log.gz">
<PatternLayout
pattern="%d{dd-MMM-YYYY HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console" />
</Root>
<Logger name="org.hkb.tryone" level="debug" additivity="false">
<AppenderRef ref="Console" />
</Logger>
<Logger name="org.hkb.trytwo" level="info" additivity="false">
<AppenderRef ref="Console" />
<AppenderRef ref="file-gen" />
</Logger>
</Loggers>
</Configuration>
What am I doing wrong here ?!
Upvotes: 2
Views: 3291
Reputation: 36754
I think your filePattern can only have one %d variable. If you have two, the rollover policy cannot determine the rollover frequency.
So, replace what you have now:
filePattern="${log-path}/%d{yyyy-MM}/demopro-%d{dd-MM-yyyy}.log.gz">
with this:
filePattern="${log-path}/$${date:yyyy-MM}/demopro-%d{dd-MM-yyyy}.log.gz">
Upvotes: 1