org.springframework.boot spring-boot-starter
SpringBoot使用以下依赖做日志记录:
org.springframework.boot spring-boot-starter-logging
总结:
1.SpringBoot底层也是使用slf4j+logback的方式进行日志记录
2.SpringBoot也把其他日志都替换成slf4j
3.中间替换包
package org.apache.logging.slf4j;
import java.net.URI;
import org.apache.logging.log4j.spi.LoggerContext;
import org.apache.logging.log4j.spi.LoggerContextFactory;
import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.util.LoaderUtil;
public class SLF4JLoggerContextFactory implements LoggerContextFactory {
private static final StatusLogger LOGGER = StatusLogger.getLogger();
private static LoggerContext context = new SLF4JLoggerContext();
public SLF4JLoggerContextFactory() {
boolean misconfigured = false;
try {
LoaderUtil.loadClass("org.slf4j.helpers.Log4jLoggerFactory");
misconfigured = true;
} catch (ClassNotFoundException var3) {
LOGGER.debug("org.slf4j.helpers.Log4jLoggerFactory is not on classpath. Good!");
}
if (misconfigured) {
throw new IllegalStateException("slf4j-impl jar is mutually exclusive with log4j-to-slf4j jar (the first routes calls from SLF4J to Log4j, the second from Log4j to SLF4J)");
}
}
public LoggerContext getContext(final String fqcn, final ClassLoader loader, final Object externalContext, final boolean currentContext) {
return context;
}
public LoggerContext getContext(final String fqcn, final ClassLoader loader, final Object externalContext, final boolean currentContext, final URI configLocation, final String name) {
return context;
}
public void removeContext(final LoggerContext ignored) {
}
}
4.如果引入其他框架,一定要把这个框架的默认日志依赖移除掉
Spring框架用的是commons-logging
org.springframework spring-core commons-logging commons-logging
SpringBoot能自动适配所有的日志,而且底层使用slf4j+logback的方式记录日志,引入其他框架的时候,只需要把这个框架依赖的日志框架排除掉



