Log4j报错 ERROR StatusLogger No Log4j 2 configuration file found.

报错

java项目使用log4j2日志,配置好依赖的包之后,编译报错,报错信息如下:

ERROR StatusLogger No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property ‘log4j2.debug’ to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2

分析

从打印的报错信息,可知缺少配置文件。

解决

在src/main/resources目录下创建log4j2.xml配置文件即可。
样例配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="error">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d %-5p (%F:%L) - %m%n" />
        </Console>
    </Appenders>

    <Loggers>
        <logger name="包名" level="info" includeLocation="true" additivity="false">
            <appender-ref ref="Console"/>
        </logger>

        <root level="info" includeLocation="true">
            <appender-ref ref="Console"/>
        </root>
    </Loggers>
</Configuration>

转载链接

Log4j报错ERROR StatusLogger No Log4j 2 configuration file found.