【问题标题】:Spring boot: ERROR StatusLogger Log4j2 could not find a logging implementationSpring boot:ERROR StatusLogger Log4j2 找不到日志记录实现
【发布时间】:2019-10-16 03:07:22
【问题描述】:

我试图将 log4j2 添加到 Spring Boot 项目,但它给出了以下错误。 错误 StatusLogger Log4j2 找不到日志记录实现。请将 log4j-core 添加到类路径中。使用 SimpleLogger 登录控制台

我已使用此链接进行了相同的配置 https://howtodoinjava.com/spring-boot2/spring-boot-log4j2-config/

package log.demo.LogDemo;

/**
 * Hello world!
 *
 */
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class Application extends SpringBootServletInitializer {


    private static final Logger LOGGER = LogManager.getRootLogger();//Application.class);

    public static void main(String[] args)
    {

        ApplicationContext ctx = SpringApplication.run(Application.class, args);

        LOGGER.info("Info level log message");
        LOGGER.debug("Debug level log message");
        LOGGER.error("Error level log message");
    }
}
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>log.demo</groupId>
    <artifactId>LogDemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>LogDemo</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
    </parent>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>



    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <excludes>
                    <!-- <exclude>application.properties</exclude> <exclude>TahitiConfig.xml</exclude> 
                        <exclude>job_definitions.xml</exclude> -->
                </excludes>
            </resource>
        </resources>

    </build>
</project>

不明白出了什么问题,任何帮助都会很棒。 如果需要更多信息,请告诉我

尝试了这个解决方案,但没有帮助 Log4j2 could not find a logging implementation with Sprint Boot

【问题讨论】:

  • 找到答案你只需要删除你的 JARS 并重新下载它。当我使用 Maven 时,我删除了 m2\repository\org\apache\logging\log4j 文件夹。它对我来说工作正常。回复链接stackoverflow.com/a/56391856/7352772

标签: spring-boot log4j2


【解决方案1】:

给你的 pom 添加依赖

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-to-slf4j</artifactId>
    <version>2.8.2</version>
</dependency>

这是因为就我而言,log4j 是从 Elasticsearch 打印的。我已经实现了 logback.xml 进行日志记录。 要克服默认的 log4j 错误消息,您可以使用 slf4j 覆盖。

【讨论】:

  • 问题是关于如何让 log4j 2 工作,而不是消除使用它。
猜你喜欢
  • 2018-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-26
  • 1970-01-01
  • 2022-11-08
  • 2021-11-19
  • 2019-08-31
相关资源
最近更新 更多