我正在尝试设置 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 中。
我不确定还需要检查什么。我也尝试过将 xml 文件移动到 /src 目录,但没有帮助。我缺少什么?
您没有指定用于部署的服务器,当我尝试在 Wildfly 8.1 上部署 Web 应用程序并将 log4j2.xml 放在 src/main/resources 文件夹中时,我也遇到了同样的问题。
中指出这个线程 https://issues.apache.org/jira/browse/LOG4J2-890这不是 log4j2 bug,而是 JBoss/Wildfly 代码中的 bug。
引用哈桑·卡拉德 (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 部署程序源代码,并且总是发现它
读取服务文件的第一行 // 这行来自
ServletContainerInitializerDeploymentProcessor.loadSci() 字符串
servletContainerInitializerClassName = reader.readLine();
所以当我手动编辑服务文件并保留最后一行时
(org.apache.logging.log4j.web.Log4jServletContainerInitializer)它
现在工作正常
无论如何,我确实将 log4j2 版本恢复到 2.0.2 并且它也能正常工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)