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我有一组使用Log4J2进行日志记录的Spring服务。日志记录是为两个捕获设置的: 1)控制台输出到文本日志文件;2)由特定类生成的输出,用于向单独的JSON文件报告统计信息。
当我通过启动脚本(在Linux上)执行服务时,输出将正确地写入它们各自的文件中。但是,当我试图从eclipse内部运行服务时(用于开发测试/调试和bug修复),输出总是出现在控制台中。从未产生过任何文件。我试过很多东西,但没什么改变。
我在控制台中看到的情况似乎表明,如果有的话,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:\Users\JO24447\workspace\REST_RST_Service\mission-services\route-generator\target\classes started by JO24447 in C:\Users\JO24447\workspace\REST_RST_Service\mission-services\route-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>
...发布于 2021-08-11 10:30:23
您可以检查以下内容
https://stackoverflow.com/questions/60619123
复制相似问题