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

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

问题描述

我正在开发一组网络服务,我们希望有一个每日轮换的日志.

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

我正在尝试从正在运行的 log4j extras 伴侣中获取 org.apache.log4j.rolling.RollingFileAppender,因为文档表明这最适合生产环境.

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 extras 库 (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 文件中为 appender 做了以下配置:

I have the following configuration for the appender in the 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?

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

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.properties

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天全站免登陆