Log4j-ERROR StatusLogger Log4j2 could not find a logging implementation
标签:开发工具

使用Log4j2,打包后提示ERROR StatusLogger Log4j2 could not find a logging implementation.

log4j.properties

# Global logging configuration
log4j.rootLogger=DEBUG, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

POM.xml

<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.8.2</version>
</dependency>

配置完成后,发现控制台输出不了日志,报错:

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...

最后查找得出:

在src下添加log4j2.component.properties文件,内容为:

log4j2.loggerContextFactory=org.apache.logging.log4j.core.impl.Log4jContextFactory

参考链接:使用Log4j2,打包后提示ERROR StatusLogger Log4j2 could not find a logging implementation.

  • 1 min read

CONTRIBUTORS


  • 1 min read