设置日志文件名以在 Log4j 中包含当前日期 [英] Setting a log file name to include current date in Log4j

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

问题描述

我想将 log4j 和 log4net appender 的日志文件名设置为具有当前日期.我们正在做每日翻转,但当前的日志文件没有日期.日志文件名格式为

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 中包含当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆