Mehman Bashirov
Mehman Bashirov

Reputation: 37

Why log4j renames filename?

I use the bellow codes.When I run project create MyLogFile.log file.

Next day I run project and log4j renames MyLogFile to MyLogFile.log_Yesterday.log and create new MyLogFile file and start to write this file.

Why It doesn't crate MyLogFile.log_ToDay.log file? Why it renames fileName? Thank in advance

log4j.rootLogger=DEBUG, stdout   
log4j.rootLogger=DEBUG, RollingAppender
log4j.appender.RollingAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingAppender.File=d:/Logs/MyLogFile.log
log4j.appender.RollingAppender.DatePattern='_'yyyy-MM-dd'.log' 
log4j.appender.RollingAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingAppender.layout.ConversionPattern=[%p] %d %c %M - %m%n

Upvotes: 0

Views: 170

Answers (1)

Aniket V
Aniket V

Reputation: 3247

The appender being used is org.apache.log4j.DailyRolling‌​FileAppender which takes a back up of the current log file whenever the date changes.

2017-08-29, The log file will be created with the name MyLogFile.log and logs will be written to it.

2017-08-30, Whenever the code encounters something to be logged, the appender will rename the file created on the previous day to MyLogFile_2017-08-29.log and create a fresh MyLogFile.log for the current day.

Please refer to the Javadoc for DailyRollingFileAppender for more details on how it works.

Upvotes: 1

Related Questions