DailyRollingFileAppender将

DailyRollingFileAppender将

本文介绍了无法使用log4j DailyRollingFileAppender将日期附加到文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 您好我正在尝试使用log4j DailyRollingFileAppender将当前日期附加到文件名,但它不起作用。我使用了如下配置。请为此建议解决方案Hi I am trying to append the current date to the file name using log4j DailyRollingFileAppender, but its not working. I have used the configuration like below. Please suggest a solution for thislog4j.rootLogger = DEBUG, rollingAppenderlog4j.appender.rollingAppender=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.rollingAppender.DatePattern='.'yyyy-MM-ddlog4j.appender.rollingAppender.File=F:/temp/app.loglog4j.appender.rollingAppender.layout=org.apache.log4j.PatternLayoutlog4j.appender.rollingAppender.layout.ConversionPattern=[%p] %d %c %M - %m%n我希望日志文件为app2014-11-07。 log,但它仍然是app.logI am expecting the log file as app2014-11-07.log, but its still app.log推荐答案如果您使用的是log4j 1.x,我们强烈建议您使用 org.apache .log4j.rolling.RollingFileAppender 1 而不是 org.apache.log4j.DailyRollingFileAppender (可能会丢失消息,错误43374 )。If you're using log4j 1.x, we strongly recommend that you use org.apache.log4j.rolling.RollingFileAppender 1 instead of org.apache.log4j.DailyRollingFileAppender (may lose messages, Bug 43374).所以你的appender的配置可以是:So the configuration of you appender can be:log4j.rootLogger = DEBUG, rollingAppenderlog4j.appender.rollingAppender=org.apache.log4j.rolling.RollingFileAppenderlog4j.appender.rollingAppender.rollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicylog4j.appender.rollingAppender.rollingPolicy.fileNamePattern=F:/temp/app%d{yyyy-MM-dd}.loglog4j.appender.rollingAppender.layout=org.apache.log4j.PatternLayoutlog4j.appender.rollingAppender.layout.ConversionPattern=[%p] %d %c %M - %m%n 注释 在这种情况下,您需要添加相应的jar( apache-log4j-extras-1.2 .17.jar )。In that case, you need to add the respective jar (apache-log4j-extras-1.2.17.jar). 这篇关于无法使用log4j DailyRollingFileAppender将日期附加到文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 13:47