logback如何发现configuration file
程序员文章站
2022-06-13 20:37:23
...
今天发现日志一直打印debug没有加载configuration file中配置的格式,通过debug找到logback记载配置的流程。
当调用
org.slf4j.LoggerFactory.getLogger(StandaloneLoggingModule.class)
的调用过程如下:
--->LoggerFactory.getLogger(Class clazz)
--->iLoggerFactory=slf4j.LoggerFactory.getILoggerFactory()
--->slf4j.LoggerFactory.performInitialization()
--->slf4j.LoggerFactory.bind()
--->org.slf4j.impl.StaticLoggerBinder.getSingleton()
--->org.slf4j.impl.StaticLoggerBinder.init()
--->new ch.qos.logback.classic.util.ContextInitializer(defaultLoggerContext).autoConfig()
--->iLoggerFactory.getLogger(name)
ch.qos.logback.classic.util.ContextInitializer.autoConfig()执行过程
--->ContextInitializer.findURLOfDefaultConfigurationFile(true)
--->ContextInitializer.findConfigFileURLFromSystemProperties(myClassLoader, updateStatus);
---> String logbackConfigFile =OptionHelper.getSystemProperty("logback.configurationFile");
---> URL result = new URL(logbackConfigFile);
---> 如果出现MalformedURLException, result = Loader.getResource(logbackConfigFile, classLoader)
--> ContextInitializer.configureByResource(url)