What configuration values are needed to setup Log4j to use the following pattern?
MyApp-Mon.log
MyApp-Tue.log
MyApp-Wed.log
Etc
With each file containing the days log.
This sounds easy enough to do with Log4j's DailyRollingFileAppender but I am having trouble.
Here is my current config;
<appender name="daily-file" class="org.apache.log4j.DailyRollingFileAppender">
<param name="Threshold" value="info"/>
<param name="DatePattern" value="'-'EE'.log'"/>
<param name="file" value="MyApp"/>
<param name="Append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{EEE MMM dd hh:mm:ss zzz yyyy} %-5p %l - %m%n"/>
</layout>
</appender>
I based this config on this blog post, but it is not behaving in the way he describes. The log is being created as MyApp with no extension.
Can anyone help me out here?
Best Answer
This is what you told Log4J to do with this line:
Log4J uses the value of this option as log file name and the pattern is only applied when the roll over occurs, as documented:
So everything looks normal to me.
To obtain the desired behavior, you could write your own
Appender
. It looks like James Stauffer did something very similar (see this answer) but he extendsFileAppender
. It should be easy to adapt his work for aDailyRollingFileAppender
subclass though.