简体   繁体   中英

How can I rollover my log file on a daily basis and when the file size exceeds max limit at the same time in log4j

I am using log4j for creating log files. I used DailyRollingFileAppender to create log files for each day. But I also need to create a new file when the file size exceeds a max limit. RollingFileAppender supports MaxFileSize property, But it doesn't work for DailyRollingFileAppender. What should I do?

Try using DailyRollingFileAppender with below configuration,

log4j.appender.infoAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.infoAppender.DatePattern='.' yyyy-MM-dd HH-mm
log4j.appender.infoAppender.Threshold=DEBUG
log4j.appender.infoAppender.File=D:/debug.log

Try making logs per hour. This may not solve your problem completely but will help for sure. DailyRollingFileAppender doesnt support file size.

http://www.tutorialspoint.com/log4j/log4j_logging_files.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM