Log4j2找不到我的配置文件

时间:2014-10-24 16:46:14

标签: maven slf4j log4j2

我试图设置SLF4J以使用Log4J2。但我一直收到这个错误:

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

以下是我的POM依赖关系:

<properties>
    <log4j.version>2.1</log4j.version>
</properties>

<!-- Logging -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.7</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>${log4j.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>${log4j.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>${log4j.version}</version>
</dependency>

我使用简单的配置进行测试:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace">
    <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="debug">
            <AppenderRef ref="Console" />
        </Root>
    </Loggers>
</Configuration>

我的log4j2.xml文件位于src / main / resources。

enter image description here

enter image description here

我不确定还有什么要检查。我也尝试将xml文件移动到/ src目录,但它没有帮助。我错过了什么?

2 个答案:

答案 0 :(得分:2)

您没有指定用于部署的服务器,当我尝试在Wildfly 8.1上部署我的Web应用程序并在src / main / resources文件夹中安装我的log4j2.xml时,我遇到了同样的问题。

this thread中指出,它不是log4j2错误,而是JBoss / Wildfly代码中的错误。

引用Hassan Kalaldeh的话:

  

如果你解压缩log4j-web-2.1.jar并打开,我发现了什么问题   servlet容器文件中的初始化程序服务:   log4j的的web-2.1 \ META-INF \ SERVICES \ javax.servlet.ServletContainerInitializer   你会发现:javax.servlet.ServletContainerInitializer

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache license, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the license for the specific language governing permissions and
# limitations under the license.
# org.apache.logging.log4j.web.Log4jServletContainerInitializer
     

我一直在阅读JBoss deployer源代码,我总是发现它   从第一行读取服务文件//此行   ServletContainerInitializerDeploymentProcessor.loadSci()字符串   servletContainerInitializerClassName = reader.readLine();

     

所以当我手动编辑服务文件并保持最后一行时   (org.apache.logging.log4j.web.Log4jServletContainerInitializer)它   现在工作正常

无论如何,我确实将我的log4j2版本还原为2.0.2并且它也正常工作。

答案 1 :(得分:1)

似乎是2.1版中的错误。我将Log4j2回滚到版本2.0.1,一切正常。

相关问题