简体   繁体   English

如何在SpringBoot中同时使用log4j和logBack?

[英]How to use log4j and logBack in SpringBoot simultaneously?

Our software uses an api (filenet p8) that requires log4j to be configured.我们的软件使用需要配置 log4j 的 api (filenet p8)。 We use logBack and Spring Boot.我们使用 logBack 和 Spring Boot。 I notice that to use log4j in Spring Boot we have to exclude logBack.我注意到要在 Spring Boot 中使用 log4j,我们必须排除 logBack。 This is not possible.这不可能。 Is there a way to run log4j and logBack in parallel in Spring Boot?有没有办法在 Spring Boot 中并行运行 log4j 和 logBack? Thanks谢谢

The spring-boot-starter-logging artifact enables the automatic configuration and redirection of many logging frameworks to Logback. spring-boot-starter-logging工件可以自动配置许多日志框架并将其重定向到 Logback。

However since Spring Boot 2.x the redirections from Log4j 1.2 and JCL to SLF4J are not installed by default.但是,从 Spring Boot 2.x 开始,默认情况下不会安装从 Log4j 1.2 和 JCL 到 SLF4J 的重定向。 You need to install:您需要安装:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>log4j-over-slf4j</artifactId>
</dependency>

which is a drop-in replacement of Log4j 1.2 that redirects everything to SLF4J (no <version> attribute needed, since Spring Boot manages it).这是 Log4j 1.2 的替代品,将所有内容重定向到 SLF4J(不需要<version>属性,因为 Spring Boot 管理它)。

You must also remove the log4j and slf4j-log4j12 artifacts, if they are present: the first one would cause random class loading ( log4j-over-slf4j has the same classes), the second one will cause an infinite loop between Log4j and SLF4J (cf. this question ).您还必须删除log4jslf4j-log4j12工件,如果它们存在:第一个会导致随机类加载( log4j-over-slf4j具有相同的类),第二个会导致 Log4j 和 SLF4J 之间的无限循环(参见这个问题)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM