Create new log file daily using log4j

天涯浪子 提交于 2019-11-27 03:29:33

问题


I want to use Log4j in my java project, which configuration should I provide in configuration file that every night at 12.00 am new file will generate and file name should like - output-log-of-MyProjectName-HostName-2013-Dec-10.txt name). My configuration file is like that-

log4j.appender.FILE = org.apache.log4j.DailyRollingFileAppender    
log4j.appender.FILE.File = ${log}/log.out    
log4j.appender.FILE.DatePattern = '.' yyyy-MM-dd-a

It is creating new file everyday but it appending date after file name. Please help me. Thanks in advance.


回答1:


I think you want DailyRollingFileAppender (geedubb links to the log4j docs about it) Here is example

Here is another stackoverflow question like yours



来源:https://stackoverflow.com/questions/20618527/create-new-log-file-daily-using-log4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!