I'm trying to append the current date to the log4j log file. So it would be something like this:
myApp-2011-01-07.log
The thing is that I do not want to use the DailyRollingFileAppender. Reason is that there will be another script that runs daily that will backup everything in the logs folder. This is running under Tomcat5.5.
Is this possible in log4j?
I think you could just set a system property in code to contain the current date:
Then in your log4j.xml file you can use the system property when specifying the log file name in the appender:
ETA: Now that I think about it you may have to setup the system property using a static initializer to make sure the property is set before log4j is configured.
you can manage this quickly and highly mantainable by just creating your own Appender.
Just create a Class like this :
and place this in your properties:
Now you can give any type of filename you want.
Try setting this in your
log4j.properties
file:much more information can be found here http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/DailyRollingFileAppender.html