在log4j中配置RollingFileAppender [英] Configuring RollingFileAppender in log4j

查看:4448
本文介绍了在log4j中配置RollingFileAppender的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一组网络服务,我们希望每天都有一个轮换日志。

I'm working on a set of web services and we'd like to have a daily rotated log.

我正试图获得 org.apache.log4j.rolling.RollingFileAppender 来自log4j extras配套工作,因为文档建议这最适合生产环境。

I'm trying to get org.apache.log4j.rolling.RollingFileAppender from the log4j extras companion working, since the documentation suggests this is best for production environments.

我有两个主log4J库( log4j-1.2.15.jar )和log4j额外库( apache-log4j-extras-1.1。类路径上的jar )。

I have both the main log4J library (log4j-1.2.15.jar) and the log4j extras library (apache-log4j-extras-1.1.jar) on the classpath.

我在 log4j.properties file:

### SOAP Request Appender
log4j.appender.request=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.request.File=SOAPmessages.log
log4j.appender.request.RollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy
log4j.appender.request.RollingPolicy.ActiveFileName =SOAPmessages-%d.log
log4j.appender.request.RollingPolicy.FileNamePattern=SOAPmessages-%d.log.zip
log4j.appender.request.layout = org.apache.log4j.PatternLayout
log4j.appender.request.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

然而,当我使用log4j启动Web服务时在调试模式下,我收到以下错误消息:

However, when I start the web service with log4j in debug mode I get these error messages:

log4j: Parsing appender named "request".
log4j: Parsing layout options for "request".
log4j: Setting property [conversionPattern] to [%d{ABSOLUTE} %5p %c{1}:%L - %m%n].
log4j: End of parsing for "request".
log4j: Setting property [file] to [/logs/SOAPmessages.log].
log4j:WARN Failed to set property [rollingPolicy] to value "org.apache.log4j.rolling.TimeBasedRollingPolicy". 
log4j:WARN Please set a rolling policy for the RollingFileAppender named 'request'
log4j: Parsed "request" options.

我找到了关于如何配置这个appender有点稀疏的文档,所以任何人都可以帮助我修复配置?

I've found documentation about how to configure this appender a little sparse, so can anyone help me fix my configuration?

EDIT0:添加了调试模式输出,而不仅仅是标准警告

Added debug mode output, rather than just the standard warnings

推荐答案

更新:至少早在2013年(参见Mubashar的评论)开始工作。

Update: at least as early as 2013 (see Mubashar's comment) this started working.

根据 Log4jXmlFormat ,你不能使用log4j.properties配置它,但只使用XML配置格式:

According to Log4jXmlFormat you cannot configure it with log4j.properties, but only using the XML config format:


请注意,TimeBasedRollingPolicy只能配置xml,而不能配置log4j。属性

Note that TimeBasedRollingPolicy can only be configured with xml, not log4j.properties

不幸的是,它们提供的示例log4j.xml也不起作用:

Unfortunately, the example log4j.xml they provide doesn't work either:

log4j:ERROR Parsing error on line 14 and column 76
log4j:ERROR Element type "rollingPolicy" must be declared.
...
log4j:WARN Please set a rolling policy for the RollingFileAppender named 'FILE'

这篇关于在log4j中配置RollingFileAppender的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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