春季启动:错误StatusLogger Log4j2找不到日志记录实现 [英] Spring boot: ERROR StatusLogger Log4j2 could not find a logging implementation

查看:95
本文介绍了春季启动:错误StatusLogger Log4j2找不到日志记录实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I trying to add log4j2 to spring boot project but it is giving below error. ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console

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

I have configured same using this link 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>

不知道出了什么问题,任何帮助都会很棒.请让我知道是否需要更多信息

Don't understand what went wrong any help will be great. Please let me know if required more information

尝试了此解决方案,但没有帮助 Log4j2找不到具有Sprint Boot的日志记录实现

Tried this solution but no help Log4j2 could not find a logging implementation with Sprint Boot

推荐答案

将依赖项添加到pom

Add dependency to your 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覆盖.

This is because for my case the log4j is printing from Elasticsearch. I have implemented logback.xml for logging. To overcome default log4j error messages, you can override with slf4j.

这篇关于春季启动:错误StatusLogger Log4j2找不到日志记录实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆