【问题标题】:ERROR StatusLogger Reconfiguration failed: No configuration found for '73d16e93' at 'null' in 'null'ERROR StatusLogger Reconfiguration failed: No configuration found for '73d16e93' at 'null' in 'null'
【发布时间】:2021-03-09 10:56:09
【问题描述】:

我正在使用 log4j2 的 jar 文件如下: log4j-api-2.14.0.jar log4j-core-2.14.0.jar log4j-slf4j-impl-2.14.0.jar

执行以下行: LogManager.getLogger("com.foo.Bar1");

使用以下 VM 参数: -Dlog4j.configuration=test1.xml

配置文件 test1.xml 如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <Console name="Console1" target="SYSTEM_OUT">
            <PatternLayout
                pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
        </Console>
        <File name="MyFile" fileName="test1.txt">
            <PatternLayout>
                <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
            </PatternLayout>
        </File>
    </Appenders>
    <Loggers>
        <Logger name="com.foo.Bar1" level="trace">
            <AppenderRef ref="Console1" />
            <AppenderRef ref="MyFile" />
        </Logger>
    </Loggers>
</Configuration>

java文件启动时出现如下错误 ERROR StatusLogger Reconfiguration failed: No configuration found for '73d16e93' at 'null' in 'null'

我了解“-Dlog4j.configuration=test1.xml”是错误的。 “-Dlog4j.configurationFile=test1.xml”是正确的。但我不明白为什么使用“-Dlog4j.configuration=test1.xml”时会出现错误。

为什么使用-Dlog4j.configuration=test1.xml时会出现错误。

【问题讨论】:

    标签: java xml log4j2


    【解决方案1】:

    这是因为log4j.configuration 期望文件位于类路径中,而log4j.configurationFile 期望它作为文件路径。

    如果您将-Dlog4j2.debug=true 添加到 VM 参数中,您可以看到它正在尝试加载哪个文件并打印其路径。这样,您就会知道错误发生的原因。

    【讨论】:

      【解决方案2】:

      Log4j 2 具有对 Log4j 1.2 配置文件的实验性支持。如果您指定 -Dlog4j.configuration,那么 Log4j 的 ConfigurationFactory 假定您希望在兼容模式下运行并查找 Log4j 1.x 格式的配置文件。如果您提供了一个 Log4j2 格式的文件显然会失败,特别是如果您的项目中没有 log4j-1.2-api,因为这是 Log4j 1.x XML 配置文件的配置类所在的位置。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-02
        • 2017-08-14
        • 1970-01-01
        • 2016-10-16
        相关资源
        最近更新 更多