Log4j - Create 1 log file per day

By xngo on June 23, 2019

Add the followings in your Log4j configuration/properties file:

log4j.rootLogger=info, R
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=filename
log4j.appender.R.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS zzz} %5p %c{1}:%L - %m%n

The filename of the log file will look like this:

filename
filename.2010-01-21.log
filename.2010-01-22.log
filename.2010-01-23.log

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.