我正在使用log4j-1.2.17 jar版本,
启动应用程序时,我在控制台中收到以下错误
log4j:WARN Continuable parsing error 38 and column 24
log4j:WARN Attribute "ref" is required and must be specified for element type "appender-ref".
log4j:WARN Continuable parsing error 47 and column 12
log4j:WARN The content of element type "root" must match "(param*,(priority|level)?,appender-ref*)".
log4j:ERROR No appender named [] could be found.
这是我编辑后的log4j.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender class="org.apache.log4j.RollingFileAppender" name="FILE">
<param value="D:\\Two\\test.log" name="File"/>
<param value="10" name="MaxBackupIndex"/>
<param value="200MB" name="MaxFileSize"/>
<layout class="org.apache.log4j.PatternLayout">
<param value="%d[%t] %-5p(%F:<%M>:%L)- %m%n" name="ConversionPattern"/>
</layout>
</appender>
<appender class="com.MyAppender" name="customAppen">
<layout class="org.apache.log4j.PatternLayout">
<param value="%d[%t] %-5p(%F:<%M>:%L)- %m%n" name="ConversionPattern"/>
</layout>
</appender>
<appender class="org.apache.log4j.AsyncAppender" name="asynchapp">
<param name="Blocking" value="false"/>
<appender-ref ref="customAppen"/>
</appender>
<root level="INFO">
<appender-ref ref="FILE"/>
<appender-ref ref="asynchapp"/>
</root>
</log4j:configuration>
答案 0 :(得分:2)
这些似乎源于<appender-ref/>
下面的<root>
行。应该删除它,因为它没有引用任何appender,你应该将你的appender-ref移动到“customAppen”appender到root标签。
答案 1 :(得分:0)
在与其他读者的问题相关时,我也认为订单很重要,所以需要保持这个顺序:
renderer*, appender*,(category|logger)*,root?, categoryFactory?
示例log4j.xml文件看起来像这样,
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!-- I created a renderer for the servlet request object so that it -->
<!-- is easy to log info about it. It's also reusable this way in all
servlets. -->
<renderer renderedClass="javax.servlet.http.HttpServletRequest"
renderingClass="com.firstpac.etools.log.HttpServletRequestRenderer"/>
<!-- All output goes to eTools logfile ($TOMCAT_HOME/logs directory) -->
<appender name="log" class="org.apache.log4j.DailyRollingFileAppender">
<layout class="org.apache.log4j.PatternLayout">
</layout>
</appender>
<!-- All output goes to DB for client statistics -->
<appender name="clientStats" class="org.apache.log4j.jdbc.JDBCAppender">
</appender>
<!-- This is our logger for the fpcServlets application. It logs all -->
<!-- info to files (error/debug...) -->
<logger name="com.firstpac.etools.log4j.log">
<level value="debug" />
<appender-ref ref="log" />
</logger>
<!-- This is our logger for the fpcServlets application. It logs all -->
<!-- statistics info for the user -->
<logger name="com.firstpac.etools.log4j.clientStats">
<level value="info" />
<appender-ref ref="clientStats" />
</logger>
</log4j:configuration>