I am trying to configure RollingFile appender in tomcat 7.0.23 with log4j2(2.0.2) with 10 log files.
I am using in the filePattern the ${sys:catalina.base}, it doesn't work and log files are placed in tomcat/bin/${sys:catalina.base}/ directory.
The interesting part is that the first log file (without a number) is created ok, under tomcat/logs - which means it succeeds to map the filename attribute to a real path.
When I replace ${sys:catalina.base} with filePattern="C:/apache-tomcat-7.0.23/logs/app.%i.log" it works.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%d %-5p [%X{REQ_ID}] [%c{1}] %m%n"/>
</Console>
<RollingFile name="FILE" fileName="${sys:catalina.base}/logs/app.log"
filePattern="${sys:catalina.base}/logs/app.%i.log">
<PatternLayout pattern="%d %-5p [%X{REQ_ID}] [%c{1}] %m%n"/>
<Policies>
<SizeBasedTriggeringPolicy size="10 MB" />
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="info">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</Root>
</Loggers>
</Configuration>
Meaning that the filePattern is not interpreted properly.
How do I overcome this without having to specify the log directory statically?
Thanks for the help
What you describe looks very much like the issue reported in LOG4J2-829. This is a bug that was introduced in the 2.0-RC2 release. It was recently fixed in master and the fix will be included in the upcoming 2.1 release. (I hope 2.1 will be released some time next week - but no promises...)
If you are in a hurry, you can check out the code from the Log4j2 GIT repository and build the 2.1-SNAPSHOT locally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With