设置日志文件名包括当前日期的Log4j

设置日志文件名包括当前日期的Log4j

本文介绍了设置日志文件名包括当前日期的Log4j的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置日志文件名的Log4j和log4net的附加目的地有当前的日期。我们正在做每日翻车,但当前的日志文件没有日期。日志文件名格式将是

I would like to set the log file name for a log4j and log4net appender to have the current date. We are doing Daily rollovers but the current log file does not have a date. The log file name format would be

logname.2008-10-10.log

任何人都知道的最好的方式为我做到这一点?

Anyone know the best way for me to do this?

编辑:我忘了提及,我们会想这样做的log4net的为好。加任何解决方案将需要在JBoss的可用

edit: I forgot to mention that we would want to do this in log4net as well. Plus any solution would need to be usable in JBoss.

推荐答案

DailyRollingFileAppender是你完全搜索。

DailyRollingFileAppender is what you exactly searching for.

<appender name="roll" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="File" value="application.log" />
    <param name="DatePattern" value=".yyyy-MM-dd" />
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern"
          value="%d{yyyy-MMM-dd HH:mm:ss,SSS} [%t] %c %x%n  %-5p %m%n"/>
    </layout>
  </appender>

这篇关于设置日志文件名包括当前日期的Log4j的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 13:32