log4j日志实现重复警告slf4j-jdk14和log4j-over-slf4j

时间:2021-08-14 06:25:39

  因为各种三方库依赖的log4j实现不同,所以可能会出现找到多个log4j实现的警告,但是不影响程序(logback是会影响的),如下:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/software/slf4j-log4j12-1.7.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/software/log4j-slf4j-impl-2.4.1.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 [org.slf4j.impl.Log4jLoggerFactory]

  这通常是因为同时包含了slf4j-log4j12和log4j-slf4j-impl,所以去掉slf4j-log4j12,保留log4j-slf4j-impl即可。警告即消失。前者还会导致log4j2的一些PATTERN如%x不生效。