log4j:无法识别的元素rollingPolicy

时间:2013-06-08 11:41:07

标签: log4j tomcat7

我有一个在Tomcat 7.0.2上运行的应用程序,并使用log4j进行日志记录。 在tomcat启动后不久,catalina.out中会出现以下消息:

INFO: Initializing log4j from [file:///export0/home/tomcat/appconf/log4j.xml]
log4j:WARN Unrecognized element rollingPolicy
log4j:WARN Please set a rolling policy for the RollingFileAppender named 'PERFFILE'
log4j:WARN Unrecognized element rollingPolicy
log4j:WARN Please set a rolling policy for the RollingFileAppender named 'FILE'

当我打印我的实际日志消息时,我会看到以下内容:

log4j:ERROR No output stream or file set for the appender named [FILE].
log4j:ERROR No output stream or file set for the appender named [PERFFILE].

这两个appender的定义如下:

 <appender name="FILE" class="org.apache.log4j.rolling.RollingFileAppender">
      <param name="Append" value="true" />
      <param name="File" value="${catalina.base}/logs/server.log" />
      <rollingPolicy class="com.myapp.logging.AgingTimeBasedRollingFilePolicy">
           <param name="fileNamePattern" value="${catalina.base}/logs/archive/server.%d{yyyy-MM-dd}.log.gz" />
           <param name="keepFilesForDays" value="30" />
      </rollingPolicy> 
      <layout class="com.myapp.logging.jboss.WebappAwarePattern">
           <param name="ConversionPattern" value="%d{ISO8601}{${server.localTimezone}} %p [%X{webapp}:%c{2}] %m%n" />
      </layout>
 </appender>

 <appender name="PERFFILE" class="org.apache.log4j.rolling.RollingFileAppender">
    <param name="Append" value="true" />
    <param name="File" value="${catalina.base}/logs/performance.log" />
    <rollingPolicy class="com.myapp.logging.AgingTimeBasedRollingFilePolicy">
        <param name="fileNamePattern" value="${catalina.base}/logs/archive/performance.%d{yyyy-MM-dd}.log.gz" />
        <param name="keepFilesForDays" value="30" />
    </rollingPolicy>
    <layout class="com.myapp.logging.jboss.WebappAwarePattern">
        <param name="ConversionPattern" value="%d{ISO8601}{${server.localTimezone}} %p [%X{webapp}:%c{2}] %throwable{0} %m%n" />
    </layout>
</appender>

我一直在努力弄清楚为什么会出现这种错误却没有结果(可能我的log4j.xml无法正确解析)

所以,为什么会发生这种情况的任何想法都将受到高度赞赏。

提前致谢!

2 个答案:

答案 0 :(得分:1)

取自the Appenders documentation page

Parameter Name    Type               Description
policy            TriggeringPolicy   The policy to use to determine
                                     if a rollover should occur.

我认为您应该将rollingPolicy替换为policy。这可能取决于您使用的是2.0还是1.2;我在1.2版本中看不到policy

答案 1 :(得分:0)

我认为您在两个可能不存在或无法通过log4j识别的appender上为 rollingPolicy类设置了错误的类或自定义类

 <rollingPolicy class="com.myapp.logging.AgingTimeBasedRollingFilePolicy">

因此,使用以下命令更改两个appender类:

<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">

apache-log4j-extras jar

提供