spring+mybatis日志

spring4默认日志是log4j, spring5默认日志是JUL
spring4下使用JCL时,如果有log4j的jar,用的具体实现类是log4j,否则用的具体实现类是JUL
spring4下使用JCL时,用的具体实现类是JUL

1、spring4下日志加载顺序


	 //循环
	for(int i=0; i<classesToDiscover.length && result == null; ++i) {
            result = createLogFromClass(classesToDiscover[i], logCategory, true);
    }
	//默认加载顺序
    private static final String[] classesToDiscover = {
   		    //"org.apache.commons.logging.impl.Log4JLogger"
            LOGGING_IMPL_LOG4J_LOGGER,
            "org.apache.commons.logging.impl.Jdk14Logger",
            "org.apache.commons.logging.impl.Jdk13LumberjackLogger",
            "org.apache.commons.logging.impl.SimpleLog"
    };

2、spring5下日志加载顺序

	public static Log getLog(String name) {
		switch (logApi) {
			case LOG4J:
				return Log4jDelegate.createLog(name);
			case SLF4J_LAL:
				return Slf4jDelegate.createLocationAwareLog(name);
			case SLF4J:
				return Slf4jDelegate.createLog(name);
			default:
				return JavaUtilDelegate.createLog(name);
		}
	}

mybatis+log4j 日志是log4j

mybatis+log4j+sping4 日志是log4j

mybatis+log4j+sping5 日志是jcl----jul

3、mybatis下日志加载顺序

  static {
    //slf4j
    tryImplementation(LogFactory::useSlf4jLogging);
    //jcl
    tryImplementation(LogFactory::useCommonsLogging);
    //log4j2
    tryImplementation(LogFactory::useLog4J2Logging);
    //log4j
    tryImplementation(LogFactory::useLog4JLogging);
    //jul
    tryImplementation(LogFactory::useJdkLogging);
    tryImplementation(LogFactory::useNoLogging);
  }

你可能感兴趣的:(spring)