Using org.apache.log4j in a Java 8 application, I want a new log file to be created every hour with name e.g.: "mylog.log.2014-09-24-18". I read I need to use DailyRollingFileAppender, but when I start the application the log file is named "mylog.log".
This is the content of my log4j.properties file:
# Set root logger level and its appenders
log4j.rootLogger=DEBUG, file
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.DatePattern='.'yyyy-MM-dd-HH
log4j.appender.file.Append=true
log4j.appender.file.File=mylog.log
log4j.appender.file.encoding=UTF-8
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Can you please let me know how I can achieve this?
I set the DatePattern to log4j.appender.file.DatePattern='.'yyyy-MM-dd-HH-mm, when I logged first time, the log wrote into mylog.log, and one minute later, log wrote into mylog.log.2014-09-24-10-42. So i think the first time your log will write into mylog.log, and an hour later, the system will generate a file named 'mylog.log.2014-09-24-10'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With