log4j属性DailyRollingFileAppender不起作用 [英] log4j properties DailyRollingFileAppender does not work

查看:2464
本文介绍了log4j属性DailyRollingFileAppender不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望每日日志的日志文件附加yyyy-dd-mm格式的日期。当我使用DailyRollingFileAppender时,不会创建新的日志文件。日志将写入同一日志文件。此外,不考虑提供的日期模式。创建的日志文件是LoggerFile.log。并且每个内容(即使在第二天)都会写入此文件。

I want daily logs with the log file appended with the date in yyyy-dd-mm format. When I use DailyRollingFileAppender, a new log file is not created. The logs are written to the same log file. Also, the date Pattern provided is not considered. The log file created is LoggerFile.log. And every content(even on the next day) is written to this file.

我正在使用log4j-1.2.17 jar。我正在使用Java开发Netbeans 7.3.1。

I am using the log4j-1.2.17 jar. I am developing in Netbeans 7.3.1 in Java.

是否有人使用此JAR并面临此类问题。请帮助!

Is there anyone using this JAR and facing such a problem. Please help!

以下是我使用的属性文件的内容:

Here is the content of the properties file I use:

# Root logger option
log4j.rootLogger=ERROR,FILE,stdout

# Define the file appender
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender

log4j.appender.FILE.File=.//..//logs//LoggerFile.log

# Define the layout for file appender
log4j.appender.FILE.DatePattern='.'yyyy-MM-dd
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS zzz} %5p     %c{1}:%L - %m%n

log4j.appender.FILE.MaxFileSize=10MB


# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L -  %m%n`


推荐答案

我对每日日志文件轮换有类似的要求..(虽然问题较旧,但认为答案会对其他人有所帮助)..

I had similar requirements of daily log file rotation.. (Though the question is older, thought the answer would help others)..

关键点:


  1. 首先,我们可以避免使用DailyRollingFileAppender 。为什么?据观察,DailyRollingFileAppender会出现同步问题和数据丢失。 log4j extras随附包括应考虑用于新部署的备选方案,并在org.apache.log4j.rolling.RollingFileAppender的文档中进行了讨论。参考:每日滚动文件附加程序的文档

  1. First of all, we can avoid using DailyRollingFileAppender. Why? DailyRollingFileAppender has been observed to exhibit synchronization issues and data loss. The log4j extras companion includes alternatives which should be considered for new deployments and which are discussed in the documentation for org.apache.log4j.rolling.RollingFileAppender. Reference: Documentation of Daily Rolling File Appender

Apache extras log4j,建议使用 org.apache.log4j.rolling.RollingFileAppender ,其中包含基于时间的滚动策略

Apache extras log4j, Would suggest to use org.apache.log4j.rolling.RollingFileAppender with the Time based rolling policy

可能会找到一个示例配置,用于基于时间的日志轮换。

May find a sample configuration for time based rotation of log.

希望这会有所帮助。

这篇关于log4j属性DailyRollingFileAppender不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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