Log4J2-从Eclipse运行时不进行日志记录


Eclipse: 2019-06 (4.12.0)
Java: 1.8.0_201
Log4J2: whatever is pulled in by spring-boot-starter-log4j2 - might be 2.11.2 (mvn dependency:tree)
Spring Boot: 2.1.6.RELEASE

我有一组SpringBoot服务,它们使用Log4J2进行日志记录。日志记录是为两个捕获设置的:1(控制台输出到文本日志文件;2(特定类生成的输出,用于向单独的JSON文件报告统计信息。

当我通过启动脚本(在Linux上(执行服务时,输出会正确地写入到它们各自的文件中。但是,当我尝试从eclipse中运行服务(用于开发测试/调试和错误修复(时,输出总是出现在控制台中。从未生成过任何文件。我尝试了很多方法,但都没有改变。

我在控制台中看到的似乎表明,如果有什么不同的话,Log4J2是,而不是用于日志记录,而是Logback。我已经在POM文件中排除了Logback,但不知何故它仍在使用。

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/JO24447/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/JO24447/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.11.2/log4j-slf4j-impl-2.11.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
.   ____          _            __ _ _
/\ / ___'_ __ _ _(_)_ __  __ _    
( ( )___ | '_ | '_| | '_ / _` |    
\/  ___)| |_)| | | | | || (_| |  ) ) ) )
'  |____| .__|_| |_|_| |___, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::        (v2.1.6.RELEASE)
2020-03-10 09:06:48.489  INFO 8204 --- [           main] e.m.l.m.s.r.ApplicationMain              : Starting ApplicationMain on 532064-MITLL with PID 8204 (C:UsersJO24447workspaceREST_RST_Servicemission-servicesroute-generatortargetclasses started by JO24447 in C:UsersJO24447workspaceREST_RST_Servicemission-servicesroute-generator)
2020-03-10 09:06:48.491  INFO 8204 --- [           main] e.m.l.m.s.r.ApplicationMain              : No active profile set, falling back to default profiles: default
...

有人知道需要做些什么才能让eclipse不使用Logback而使用Log4J2吗?

以下是父POM文件的依赖项部分:

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</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-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<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-data-rest</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<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-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
...

您可以检查

  1. 如果您已经排除了春季启动程序登录您的pom
  2. 如果您看到控制台中存在多个绑定,请验证它来自哪个项目。(在我的案例中,我有一个依赖项目,它导致了重复的依赖关系(
  3. 检查eclipse中的引用库是否有任何重复的jar引用。您可能会看到显示了多个JAR。您可以删除不需要的引用

最新更新