Log4j2 找不到我的配置文件

2023-12-30

我正在尝试设置 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(使用前将#替换为@)

Log4j2 找不到我的配置文件 的相关文章

随机推荐

  • 如何计算两个相机之间的旋转和平移?

    我知道棋盘相机校准技术 并且已经实现了 如果我有两个摄像机观看同一场景 并且我使用棋盘技术同时校准两个摄像机 我可以计算它们之间的旋转矩阵和平移向量吗 如何 如果您有对应点的 3D 相机坐标 则可以通过以下方式计算最佳旋转矩阵和平移向量刚体
  • Android 自定义 XML 文件的放置

    我有一个很大的 XML 文件 其排列方式如下
  • 如何更改 PHP 常量? [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我正在用 PHP 手工制作我自己的自定义 CMS 并且我已经定义了一些常量 有没有简单的方法来修改常量 我正在考虑使用类似的东西fop
  • 为什么找不到静态库头?

    我用过克林特 哈里斯的教程 http www clintharris net 2009 iphone app shared libraries 在项目之间设置代码共享 一切都在我的计算机上按预期运行 但是在我同事的机器上 编译器在构建时似乎
  • 播放声音有一点延迟

    我的应用程序中有一个声音 当出现视图时会自动启动 但是 正如标题所说 我希望声音开始时有一点延迟 大约在视图出现后半秒 我尝试使用 PlayAtTime 但是它不起作用或者我设置了错误 这是我的代码 var player AVAudioPl
  • React-Navigation 3:使用 createBottomTabNavigator 和 createStackNavigator 打开模式

    我知道这个问题以前曾被问过 但仅限于旧版本的反应导航 从那时起 一些事情发生了变化 createBottomTabNavigator可以更快地创建底部导航器和功能jumpToIndex 不存在了 我的问题是如何创建一个类似 Instagra
  • 根据一列删除重复项并在 Google 表格中保留最新条目

    我正在研究一些自动化 并希望通过根据第三列进行比较来删除我的谷歌工作表中的重复行 我发现一个代码可以完美运行 但它不会删除工作表中的旧条目 而是删除最新的条目 我想保留最新的而不是重复的 这是我为 appscript 找到的代码Cooper
  • Python - 如何使该代码异步?

    这是一些说明我的问题的代码 def blocking1 while True yield first blocking function example def blocking2 while True yield second block
  • SmartGWT ListGrid 很慢,但仅限于 Internet Explorer

    我们已经从 gwtext 迁移到 SmartGWT 总体体验还不错 然而 我们在使用 SmartGWT 的 ListGrid 组件时遇到了很大的问题 如果满足以下两个条件 则速度非常慢 使用 Internet Explorer 5 列或更多
  • 如何在 Django 模型中存储字符串数组?

    我正在构建一个 Django 数据模型 并且希望能够在其中一个变量中存储一组字符串 我怎样才能做到这一点 e g class myClass models Model title models CharField max length 50
  • 将 BLOB(图像)从 oracle 导入到 hive

    我正在尝试使用下面的 Sqoop 命令将 BLOB Image 数据从 oracle 导入到 Hive sqoop import connect jdbc oracle thin host username password m 3 tab
  • 使用 Fusion Table 时有哪些技术限制?

    我正在寻找有关使用 Fusion Tables 时的技术限制的信息 Fusion Table 中可以存储多少行 可以针对 Fusion Table 同时运行多少个查询 读 写 我找不到任何信息https developers google
  • 在 HTML 末尾或“onload”时初始化 JS 组件?

    有一段时间 我一直在通过等待 onload 事件触发并执行一个 JavaScript 组件初始化来运行main 各种各样的 它看起来更干净 并且您可以确定 DOM 的 ID 状态是有序的 但经过一段时间的测试后 我发现组件的初始化被加载期间
  • 编码为 JSON 时 Golang 错误类型为空

    我正在尝试为 REST api 编码一些 JSON 除了一些错误之外 一切正常 例如 使用以下结构 type TemplateResponse struct Message string Error error Template Templ
  • R -应用-将许多列从数字转换为因子

    我需要将许多数字列转换为因子类型 示例表 df lt data frame A 1 10 B 2 11 C 3 12 我尝试过应用 cols lt c A B df cols lt apply df cols 2 function x as
  • WP7 Bing 地图图钉 - 如何调整自定义图钉的位置?

    好吧 简单的问题 但我还没有找到明显简单的答案 我有一个带有地图集成的 Windows Phone 7 应用程序 地图上有一组图钉 图钉是定制的 只是椭圆形 圆形 不幸的是 自定义图钉的位置与地理位置 偏离 当你放大时 它会越来越接近准确
  • 可重复使用的Barrier解决方案陷入僵局?

    我一直在读 The Little Book of Semaphores 第 41 页有一个针对可重用屏障问题的解决方案 我遇到的问题是为什么它不会产生死锁情况 1 rendezvous 2 3 mutex wait 4 count 1 5
  • 安装 PECL 包时出错:Mysql_xdevapi

    当我运行此命令时出现以下错误 sudo pecl install mysql xdevapi Error private tmp pear temp pear build nabilashahidhnTBCl mysql xdevapi 8
  • 将项目添加到组合框

    我正在尝试向组合框添加一些项目 如 msdn 网站上所示 但它向我抛出空引用异常 comboBox1 Items Add test 我尝试将其更改为 ComboBox combobox1 new ComboBox object test n
  • Log4j2 找不到我的配置文件

    我正在尝试设置 SLF4J 以与 Log4J2 一起使用 但我不断收到此错误 ERROR StatusLogger No log4j2 configuration file found Using default configuration