我正在尝试使用xml配置log4j。 我使用的是log4j1.2.13.jar和apache-log4j-extras-1.2.17.jar。
下面的是xml。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="R" class="org.apache.log4j.rolling.RollingFileAppender">
<param name="File" value="${LOG_FILE}"/>
<param name="append" value="true"/>
<param name="encoding" value="UTF-8"/>
<layout class="org.apache.log4j.TTCCLayout">
<param name="ContextPrinting" value="true"/>
<param name="ThreadPrinting" value="true"/>
<param name="DateFormat" value="MM/dd/yyyy HH:mm:ss"/>
</layout>
<rollingPolicy class="org.apache.log4j.rolling.FixedWindowRollingPolicy">
<param name="FileNamePattern" value="${LOG_FILE}%i.gz" />
</rollingPolicy>
<triggeringPolicy class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
<param name="MaxFileSize" value="${LOG_FILESIZE_LIMIT}"/>
</triggeringPolicy>
</appender>
<root>
<priority value ="DEBUG"/>
<appender-ref ref="R"/>
</root>
</log4j:configuration>
但它没有为项目生成日志。以下是错误::
log4j:WARN Continuable parsing error 15 and column 78
log4j:WARN Element type "rollingPolicy" must be declared.
log4j:WARN Continuable parsing error 18 and column 79
log4j:WARN Element type "triggeringPolicy" must be declared.
log4j:WARN Continuable parsing error 21 and column 15
log4j:WARN The content of element type "appender" must match "(errorHandler?,param*,layout?,filter*,appender-ref*)".
log4j:WARN Please set a rolling policy for the RollingFileAppender named 'R'
level::: 7
log4j:ERROR No output stream or file set for the appender named [R].
请帮我解决这个问题。
答案 0 :(得分:0)
尝试使用
org.apache.log4j.RollingFileAppender
而不是
org.apache.log4j.rolling.RollingFileAppender
并检查此帖子是否有更多Rolling issue log4J
答案 1 :(得分:0)
根据答案: https://stackoverflow.com/a/13037467/874672
您需要使用比log4j-1.2.14.jar更新的log4j.jar版本。