尝试从页面使用示例XML文件“Sample 1 / Log4j 2 XML configuration”:
http://logging.apache.org/log4j/2.x/manual/migration.html
但它给出了:
2013-09-25 02:22:59,182 ERROR Root contains an invalid element or attribute "AppenderRef"
有什么想法吗?
我在pom.xml中使用这种依赖,
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0-beta8</version>
</dependency>
我在课堂上使用它:
private static final Logger logger = LogManager.getLogger(App.class.getName());
我按如下方式指定配置文件:
java -Dlog4j.configurationFile=log4j2.xml -jar target/project-jar-with-dependencies.jar
答案 0 :(得分:3)
这是2.0-beta8的错误,它不存在于2.0-beta9
以下是使用beta9的输出
LOG.debug("Log4j Impl test started...");
LOG.warn(" Log4j Impl test warn...");
LOG.info(" Log4j Impl test info...");
LOG.error(" Log4j Impl test error...");
...
2013-09-24 16:37:39,841 DEBUG [main] Log4jImplTest (Log4jImplTest.java:21) - Log4j Impl test started...
2013-09-24 16:37:39,843 WARN [main] Log4jImplTest (Log4jImplTest.java:22) - Log4j Impl test warn...
2013-09-24 16:37:39,843 INFO [main] Log4jImplTest (Log4jImplTest.java:23) - Log4j Impl test info...
2013-09-24 16:37:39,843 ERROR [main] Log4jImplTest (Log4jImplTest.java:24) - Log4j Impl test error...
以下是使用beta8的输出:
2013-09-24 16:39:28,233 ERROR Root contains an invalid element or attribute "AppenderRef"