日志文件名以包含log4j中的当前日期 [英] Log file name to include current date in log4j

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

问题描述

问题是这个问题的一个子集
我希望每天使用日志文件名格式创建一个日志文件,如下所示:
downloadmanageryyyy-MM-dd.log

使用 DailyRollingAppender 但根本不创建日志文件。

The question is a subset of this. I want a log file to be created everyday with the log file name format as follows: downloadmanageryyyy-MM-dd.log
Using DailyRollingAppenderbut the log file is not created at all.

我的lo4j.xml如下所示:

My lo4j.xml looks like this:

 <?xml version="1.0" encoding="UTF-8" ?>
                         <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
   <log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
   <appender name="InfoLogFile" class="org.apache.log4j.DailyRollingFileAppender">
       <param name="File" value="downloadmanager.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:configuration>


推荐答案

DailyRollingFileAppender 使用log4j发货不会重命名日志文件,直到午夜后的某个时间记录第一条消息。

The DailyRollingFileAppender shipping with log4j will not rename the log file until the first message is logged some time after midnight.

您可以尝试使用 DatedFileAppender ,可以从此处。与 DailyRollingFileAppender 相反,它将创建日志文件,其文件名始终包含今天的日期。

You may try to use DatedFileAppender , which can be download from here. Contrary to the DailyRollingFileAppender , it will create the log file whose filename always contains today's date.

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

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