Hi I am trying to append the current date to the file name using log4j DailyRollingFileAppender, but its not working. I have used the configuration like below. Please suggest a solution for this
properties
log4j.rootLogger = DEBUG, rollingAppender
log4j.appender.rollingAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.rollingAppender.DatePattern='.'yyyy-MM-dd
log4j.appender.rollingAppender.File=F:/temp/app.log
log4j.appender.rollingAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.rollingAppender.layout.ConversionPattern=[%p] %d %c %M - %m%n
I am expecting the log file as app2014-11-07.log, but its still app.log
DailyRollingFileAppender means archiving log files.
For example, today is 2014.11.07, when you first run your app, your log file name would be
app.log
. Tomorrow, you run the app again,it's log file also namedapp.log
, but yesterday's log file has been changed , maybe likeapp.log.2014.11.07
Try this :
F:/temp/
OR
Change this
to
That means it will produce a new log file minute-by-minute.
Run it again.
You can use this configuration:
If you're using log4j 1.x, we strongly recommend that you use
org.apache.log4j.rolling.RollingFileAppender
1 instead oforg.apache.log4j.DailyRollingFileAppender
(may lose messages, Bug 43374).So the configuration of you appender can be:
Notes