春季启动:错误StatusLogger Log4j2找不到日志记录实现

时间:2019-05-30 12:45:51

标签: spring-boot log4j2

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

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

Institutions
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");
    }
}

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

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

1 个答案:

答案 0 :(得分:0)

为您的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覆盖。

相关问题