如题,为什么springboot日志配置文件叫logback-spring.xml?
在整个项目中搜索 logback-spring.xml 并没有搜索到。
先看一下
org.springframework.boot.context.logging.LoggingApplicationListener#initialize
java
protected void initialize(ConfigurableEnvironment environment, ClassLoader classLoader) {
// 省略
initializeSystem(environment, this.loggingSystem, this.logFile);
// ... 省略
}
会走到
org.springframework.boot.logging.AbstractLoggingSystem#initializeWithConventions
如下代码完成 日志配置文件的定位,最终获取到 logback-spring.xml日志配置文件咯
java
@Override
protected String[] getStandardConfigLocations() {
return new String[] { "logback-test.groovy", "logback-test.xml", "logback.groovy", "logback.xml" };
}
protected String[] getSpringConfigLocations() {
String[] locations = getStandardConfigLocations();
for (int i = 0; i < locations.length; i++) {
String extension = StringUtils.getFilenameExtension(locations[i]);
locations[i] = locations[i].substring(0, locations[i].length() - extension.length() - 1) + "-spring."
+ extension;
}
return locations;
}