我开始在我的项目中使用log4j,现在我有了这个配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<log4j:configuration debug="true" xmlns:log4j="http://jakarta.apache.org/log4j/">
<appenders>
<console name="Console" target="SYSTEM_OUT">
<patternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</console>
</appenders>
<loggers>
<root level="error">
<appenderRef ref="Console"/>
</root>
</loggers>
</log4j:configuration>
但是当我部署应用程序时,我收到此错误:
log4j:WARN Continuable parsing error 2 and column 82
log4j:WARN O elemento-raiz do documento "log4j:configuration" deve corresponder à raiz de DOCTYPE "null".
log4j:WARN Continuable parsing error 2 and column 82
log4j:WARN O documento é inválido: nenhuma gramática encontrada.
log4j:WARN Unrecognized element appenders
log4j:WARN Unrecognized element loggers
同时显示这两条消息:
log4j: reset attribute= "".
log4j: Threshold ="".
任何人都知道这种配置有什么问题?
答案 0 :(得分:0)
删除
xmlns:log4j="http://jakarta.apache.org/log4j/"
并删除配置标记上的log4j前缀
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<appenders>
<console name="Console" target="SYSTEM_OUT">
<patternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</console>
</appenders>
<loggers>
<root level="error">
<appenderRef ref="Console"/>
</root>
</loggers>
</configuration>
答案 1 :(得分:0)
好的,在网上进行了更多搜索之后,我找到了一个有效的例子(official site中可用的例子不适用于我)。这是适合我的文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %c{1} - %m%n"/>
</layout>
</appender>
<root>
<priority value ="debug" />
<appender-ref ref="console" />
</root>
</log4j:configuration>