The file created today will not have date appended. If you change the system date and run the application then the new file with log.txt will be created and old file will be appended with date.
Why can't create newly log file including daily date by using DailyRollingFileAppender?
-
07-07-2023 - |
Question
I'm trying to configure log4j framework by using appender, "DailyRollingFileAppender" and want to create newly log file including daily date like {log.txt.2014-04-22", but it failed.
Here is my log4j.properties.
logPath=c:\\
logFilename=log.txt
log4j.rootLogger=DEBUG, FILE
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.File=${logPath}${logFilename}
log4j.appender.FILE.ImmediateFlush=true
log4j.appender.FILE.Append=true
log4j.appender.FILE.DatePattern='.'yyyy-MM-dd
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} | %p | %C | %M:%L | %m%n%n
Although I succeed to make a test through junit, the log file was not created like "log.txt.2014-04-22". It was created as "log.txt"
What am I missing ? please give me an advice. Thanks a lot.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow