gpt4 book ai didi

spring-boot - Spring Boot : ERROR StatusLogger Log4j2 could not find a logging implementation

转载 作者:行者123 更新时间:2023-12-04 13:58:38 46 4
gpt4 key购买 nike

我试图将 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

最佳答案

将依赖添加到你的 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 进行覆盖。

关于spring-boot - Spring Boot : ERROR StatusLogger Log4j2 could not find a logging implementation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56378595/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com