fix: resolve SpringBoot-LogSystem.md (#77)

pull/78/head
Yang Libin 4 years ago committed by GitHub
parent d609c2daa6
commit 012bd99394
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,21 +9,21 @@
- 日志级别: `org.springframework.boot.logging.LogLevel` - 日志级别: `org.springframework.boot.logging.LogLevel`
```java ```java
public enum LogLevel { public enum LogLevel {
TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF
} }
``` ```
## java 日志实现 ## Java 日志实现
- `org.springframework.boot.logging.java.JavaLoggingSystem` - `org.springframework.boot.logging.java.JavaLoggingSystem`
![image-20200323144523848](../../images/SpringBoot/image-20200323144523848.png) ![image-20200323144523848](../../images/SpringBoot/image-20200323144523848.png)
```JAVA ```java
static { static {
// KEY : springBoot 定义的日志级别, value: jdk 定义的日志级别 // KEY : springBoot 定义的日志级别, value: jdk 定义的日志级别
LEVELS.map(LogLevel.TRACE, Level.FINEST); LEVELS.map(LogLevel.TRACE, Level.FINEST);
LEVELS.map(LogLevel.DEBUG, Level.FINE); LEVELS.map(LogLevel.DEBUG, Level.FINE);
LEVELS.map(LogLevel.INFO, Level.INFO); LEVELS.map(LogLevel.INFO, Level.INFO);
@ -32,24 +32,22 @@ public enum LogLevel {
LEVELS.map(LogLevel.FATAL, Level.SEVERE); LEVELS.map(LogLevel.FATAL, Level.SEVERE);
LEVELS.map(LogLevel.OFF, Level.OFF); LEVELS.map(LogLevel.OFF, Level.OFF);
} }
``` ```
- LEVELS 对象 - LEVELS 对象
```java ```java
protected static class LogLevels<T> { protected static class LogLevels<T> {
/**
/** * key SpringBoot 中定义的日志级别, value: 其他日志框架的日志级别
* key SpringBoot 中定义的日志级别, value: 其他日志框架的日志级别 */
*/ private final Map<LogLevel, T> systemToNative;
private final Map<LogLevel, T> systemToNative; /**
* key : 其他日志框架的日志级别 , value: springBoot 中定义中定义的日志级别
/** */
* key : 其他日志框架的日志级别 , value: springBoot 中定义中定义的日志级别 private final Map<T, LogLevel> nativeToSystem;
*/ }
private final Map<T, LogLevel> nativeToSystem; ```
}
```
## LoggingSystem ## LoggingSystem
@ -58,7 +56,7 @@ public enum LogLevel {
- 一个 map 对象: `SYSTEMS` - 一个 map 对象: `SYSTEMS`
```JAVA ```java
/** /**
* key: 第三方日志框架的类 value: springBoot 中的处理类 * key: 第三方日志框架的类 value: springBoot 中的处理类
*/ */
@ -72,59 +70,58 @@ public enum LogLevel {
systems.put("java.util.logging.LogManager", "org.springframework.boot.logging.java.JavaLoggingSystem"); systems.put("java.util.logging.LogManager", "org.springframework.boot.logging.java.JavaLoggingSystem");
SYSTEMS = Collections.unmodifiableMap(systems); SYSTEMS = Collections.unmodifiableMap(systems);
} }
```
```
- 各个抽象方法 - 各个抽象方法
| 方法名称 | 作用 | | 方法名称 | 作用 |
| ----------------------- | ---------------------------------- | | ----------------------- | ---------------------------------- |
| beforeInitialize | 初始化之前调用,目的是减少日志输出 | | beforeInitialize | 初始化之前调用,目的是减少日志输出 |
| initialize | 初始化日志 | | initialize | 初始化日志 |
| cleanUp | 清除日志 | | cleanUp | 清除日志 |
| getShutdownHandler | | | getShutdownHandler | |
| getSupportedLogLevels | 获取支持的日志级别 | | getSupportedLogLevels | 获取支持的日志级别 |
| setLogLevel | 设置日志级别 | | setLogLevel | 设置日志级别 |
| getLoggerConfigurations | 获取日志配置 | | getLoggerConfigurations | 获取日志配置 |
### get ### get
```java ```java
public static LoggingSystem get(ClassLoader classLoader) { public static LoggingSystem get(ClassLoader classLoader) {
// 获取系统属性 // 获取系统属性
String loggingSystem = System.getProperty(SYSTEM_PROPERTY); String loggingSystem = System.getProperty(SYSTEM_PROPERTY);
if (StringUtils.hasLength(loggingSystem)) { if (StringUtils.hasLength(loggingSystem)) {
// 是不是NONE // 是不是NONE
if (NONE.equals(loggingSystem)) { if (NONE.equals(loggingSystem)) {
// 空的日志系统 // 空的日志系统
return new NoOpLoggingSystem(); return new NoOpLoggingSystem();
}
return get(classLoader, loggingSystem);
} }
// 循环所有日志, return get(classLoader, loggingSystem);
return SYSTEMS.entrySet().stream().filter((entry) -> ClassUtils.isPresent(entry.getKey(), classLoader))
.map((entry) ->
// 实例化具体日志
get(classLoader, entry.getValue())).findFirst()
.orElseThrow(() -> new IllegalStateException("No suitable logging system located"));
} }
// 循环所有日志,
return SYSTEMS.entrySet().stream().filter((entry) -> ClassUtils.isPresent(entry.getKey(), classLoader))
.map((entry) ->
// 实例化具体日志
get(classLoader, entry.getValue())).findFirst()
.orElseThrow(() -> new IllegalStateException("No suitable logging system located"));
}
``` ```
- 实例化日志系统 - 实例化日志系统
```java ```java
private static LoggingSystem get(ClassLoader classLoader, String loggingSystemClass) { private static LoggingSystem get(ClassLoader classLoader, String loggingSystemClass) {
try { try {
Class<?> systemClass = ClassUtils.forName(loggingSystemClass, classLoader); Class<?> systemClass = ClassUtils.forName(loggingSystemClass, classLoader);
Constructor<?> constructor = systemClass.getDeclaredConstructor(ClassLoader.class); Constructor<?> constructor = systemClass.getDeclaredConstructor(ClassLoader.class);
constructor.setAccessible(true); constructor.setAccessible(true);
return (LoggingSystem) constructor.newInstance(classLoader); return (LoggingSystem) constructor.newInstance(classLoader);
}
catch (Exception ex) {
throw new IllegalStateException(ex);
}
} }
catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
``` ```
@ -138,29 +135,28 @@ public static LoggingSystem get(ClassLoader classLoader) {
![image-20200323154205484](../../images/SpringBoot/image-20200323154205484.png) ![image-20200323154205484](../../images/SpringBoot/image-20200323154205484.png)
- 链路 - 链路
1. `org.springframework.boot.context.logging.LoggingApplicationListener#onApplicationEvent` 1. `org.springframework.boot.context.logging.LoggingApplicationListener#onApplicationEvent`
2. `org.springframework.boot.context.logging.LoggingApplicationListener#onApplicationStartingEvent` 2. `org.springframework.boot.context.logging.LoggingApplicationListener#onApplicationStartingEvent`
3. `org.springframework.boot.logging.LoggingSystem#beforeInitialize` 3. `org.springframework.boot.logging.LoggingSystem#beforeInitialize`
- 因为前文中我们已知对象是:`org.springframework.boot.logging.logback.LogbackLoggingSystem` 直接看这个类的**`beforeInitialize`**方法
```JAVA
@Override
public void beforeInitialize() {
// 日志上下文
LoggerContext loggerContext = getLoggerContext();
// 是否初始化
if (isAlreadyInitialized(loggerContext)) {
return;
}
// 父类方法
super.beforeInitialize();
// 添加过滤器
loggerContext.getTurboFilterList().add(FILTER);
}
``` - 因为前文中我们已知对象是:`org.springframework.boot.logging.logback.LogbackLoggingSystem` 直接看这个类的 `beforeInitialize` 方法
```java
@Override
public void beforeInitialize() {
// 日志上下文
LoggerContext loggerContext = getLoggerContext();
// 是否初始化
if (isAlreadyInitialized(loggerContext)) {
return;
}
// 父类方法
super.beforeInitialize();
// 添加过滤器
loggerContext.getTurboFilterList().add(FILTER);
}
```
- 初始化之前的的操作完成了初始化方法开始 - 初始化之前的的操作完成了初始化方法开始
@ -168,132 +164,129 @@ public static LoggingSystem get(ClassLoader classLoader) {
- `org.springframework.boot.context.logging.LoggingApplicationListener#onApplicationEnvironmentPreparedEvent` - `org.springframework.boot.context.logging.LoggingApplicationListener#onApplicationEnvironmentPreparedEvent`
```JAVA ```java
private void onApplicationEnvironmentPreparedEvent(ApplicationEnvironmentPreparedEvent event) { private void onApplicationEnvironmentPreparedEvent(ApplicationEnvironmentPreparedEvent event) {
if (this.loggingSystem == null) { if (this.loggingSystem == null) {
this.loggingSystem = LoggingSystem.get(event.getSpringApplication().getClassLoader()); this.loggingSystem = LoggingSystem.get(event.getSpringApplication().getClassLoader());
}
initialize(event.getEnvironment(), event.getSpringApplication().getClassLoader());
} }
initialize(event.getEnvironment(), event.getSpringApplication().getClassLoader());
}
``` ```
- `org.springframework.boot.context.logging.LoggingApplicationListener#initializeSystem` - `org.springframework.boot.context.logging.LoggingApplicationListener#initializeSystem`
```JAVA ```java
protected void initialize(ConfigurableEnvironment environment, ClassLoader classLoader) { protected void initialize(ConfigurableEnvironment environment, ClassLoader classLoader) {
new LoggingSystemProperties(environment).apply(); new LoggingSystemProperties(environment).apply();
this.logFile = LogFile.get(environment); this.logFile = LogFile.get(environment);
if (this.logFile != null) { if (this.logFile != null) {
this.logFile.applyToSystemProperties(); this.logFile.applyToSystemProperties();
}
this.loggerGroups = new LoggerGroups(DEFAULT_GROUP_LOGGERS);
// 早期 的日志级别
initializeEarlyLoggingLevel(environment);
// 初始化日志系统
initializeSystem(environment, this.loggingSystem, this.logFile);
// 初始化日志级别
initializeFinalLoggingLevels(environment, this.loggingSystem);
registerShutdownHookIfNecessary(environment, this.loggingSystem);
} }
this.loggerGroups = new LoggerGroups(DEFAULT_GROUP_LOGGERS);
// 早期 的日志级别
initializeEarlyLoggingLevel(environment);
// 初始化日志系统
initializeSystem(environment, this.loggingSystem, this.logFile);
// 初始化日志级别
initializeFinalLoggingLevels(environment, this.loggingSystem);
registerShutdownHookIfNecessary(environment, this.loggingSystem);
}
``` ```
```JAVA ```java
private void initializeSystem(ConfigurableEnvironment environment, LoggingSystem system, LogFile logFile) { private void initializeSystem(ConfigurableEnvironment environment, LoggingSystem system, LogFile logFile) {
LoggingInitializationContext initializationContext = new LoggingInitializationContext(environment); LoggingInitializationContext initializationContext = new LoggingInitializationContext(environment);
String logConfig = environment.getProperty(CONFIG_PROPERTY); String logConfig = environment.getProperty(CONFIG_PROPERTY);
if (ignoreLogConfig(logConfig)) { if (ignoreLogConfig(logConfig)) {
// 日志系统初始化 // 日志系统初始化
system.initialize(initializationContext, null, logFile); system.initialize(initializationContext, null, logFile);
}
else {
try {
ResourceUtils.getURL(logConfig).openStream().close();
system.initialize(initializationContext, logConfig, logFile);
} }
else { catch (Exception ex) {
try { // NOTE: We can't use the logger here to report the problem
ResourceUtils.getURL(logConfig).openStream().close(); System.err.println("Logging system failed to initialize using configuration from '" + logConfig + "'");
system.initialize(initializationContext, logConfig, logFile); ex.printStackTrace(System.err);
} throw new IllegalStateException(ex);
catch (Exception ex) {
// NOTE: We can't use the logger here to report the problem
System.err.println("Logging system failed to initialize using configuration from '" + logConfig + "'");
ex.printStackTrace(System.err);
throw new IllegalStateException(ex);
}
} }
} }
}
``` ```
- `org.springframework.boot.logging.logback.LogbackLoggingSystem#initialize` - `org.springframework.boot.logging.logback.LogbackLoggingSystem#initialize`
```java ```java
@Override @Override
public void initialize(LoggingInitializationContext initializationContext, String configLocation, LogFile logFile) { public void initialize(LoggingInitializationContext initializationContext, String configLocation, LogFile logFile) {
LoggerContext loggerContext = getLoggerContext(); LoggerContext loggerContext = getLoggerContext();
if (isAlreadyInitialized(loggerContext)) { if (isAlreadyInitialized(loggerContext)) {
return; return;
} }
// 日志初始化 // 日志初始化
super.initialize(initializationContext, configLocation, logFile); super.initialize(initializationContext, configLocation, logFile);
loggerContext.getTurboFilterList().remove(FILTER); loggerContext.getTurboFilterList().remove(FILTER);
markAsInitialized(loggerContext); markAsInitialized(loggerContext);
if (StringUtils.hasText(System.getProperty(CONFIGURATION_FILE_PROPERTY))) { if (StringUtils.hasText(System.getProperty(CONFIGURATION_FILE_PROPERTY))) {
getLogger(LogbackLoggingSystem.class.getName()).warn("Ignoring '" + CONFIGURATION_FILE_PROPERTY getLogger(LogbackLoggingSystem.class.getName()).warn("Ignoring '" + CONFIGURATION_FILE_PROPERTY
+ "' system property. Please use 'logging.config' instead."); + "' system property. Please use 'logging.config' instead.");
} }
} }
``` ```
- `org.springframework.boot.logging.AbstractLoggingSystem#initializeWithConventions` - `org.springframework.boot.logging.AbstractLoggingSystem#initializeWithConventions`
```JAVA ```java
private void initializeWithConventions(LoggingInitializationContext initializationContext, LogFile logFile) { private void initializeWithConventions(LoggingInitializationContext initializationContext, LogFile logFile) {
String config = getSelfInitializationConfig(); String config = getSelfInitializationConfig();
if (config != null && logFile == null) { if (config != null && logFile == null) {
// self initialization has occurred, reinitialize in case of property changes // self initialization has occurred, reinitialize in case of property changes
reinitialize(initializationContext); reinitialize(initializationContext);
return; return;
} }
if (config == null) { if (config == null) {
config = getSpringInitializationConfig(); config = getSpringInitializationConfig();
} }
if (config != null) { if (config != null) {
loadConfiguration(initializationContext, config, logFile); loadConfiguration(initializationContext, config, logFile);
return; return;
}
// 加载默认配置
loadDefaults(initializationContext, logFile);
} }
// 加载默认配置
loadDefaults(initializationContext, logFile);
}
```
- `org.springframework.boot.logging.logback.LogbackLoggingSystem#loadDefaults`
```java
@Override
protected void loadDefaults(LoggingInitializationContext initializationContext, LogFile logFile) {
LoggerContext context = getLoggerContext();
stopAndReset(context);
boolean debug = Boolean.getBoolean("logback.debug");
if (debug) {
StatusListenerConfigHelper.addOnConsoleListenerInstance(context, new OnConsoleStatusListener());
}
LogbackConfigurator configurator = debug ? new DebugLogbackConfigurator(context)
: new LogbackConfigurator(context);
Environment environment = initializationContext.getEnvironment();
context.putProperty(LoggingSystemProperties.LOG_LEVEL_PATTERN,
environment.resolvePlaceholders("${logging.pattern.level:${LOG_LEVEL_PATTERN:%5p}}"));
context.putProperty(LoggingSystemProperties.LOG_DATEFORMAT_PATTERN, environment.resolvePlaceholders(
"${logging.pattern.dateformat:${LOG_DATEFORMAT_PATTERN:yyyy-MM-dd HH:mm:ss.SSS}}"));
context.putProperty(LoggingSystemProperties.ROLLING_FILE_NAME_PATTERN, environment
.resolvePlaceholders("${logging.pattern.rolling-file-name:${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz}"));
new DefaultLogbackConfiguration(initializationContext, logFile).apply(configurator);
context.setPackagingDataEnabled(true);
}
``` ```
- `org.springframework.boot.logging.logback.LogbackLoggingSystem#loadDefaults` ```java
```JAVA
@Override
protected void loadDefaults(LoggingInitializationContext initializationContext, LogFile logFile) {
LoggerContext context = getLoggerContext();
stopAndReset(context);
boolean debug = Boolean.getBoolean("logback.debug");
if (debug) {
StatusListenerConfigHelper.addOnConsoleListenerInstance(context, new OnConsoleStatusListener());
}
LogbackConfigurator configurator = debug ? new DebugLogbackConfigurator(context)
: new LogbackConfigurator(context);
Environment environment = initializationContext.getEnvironment();
context.putProperty(LoggingSystemProperties.LOG_LEVEL_PATTERN,
environment.resolvePlaceholders("${logging.pattern.level:${LOG_LEVEL_PATTERN:%5p}}"));
context.putProperty(LoggingSystemProperties.LOG_DATEFORMAT_PATTERN, environment.resolvePlaceholders(
"${logging.pattern.dateformat:${LOG_DATEFORMAT_PATTERN:yyyy-MM-dd HH:mm:ss.SSS}}"));
context.putProperty(LoggingSystemProperties.ROLLING_FILE_NAME_PATTERN, environment
.resolvePlaceholders("${logging.pattern.rolling-file-name:${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz}"));
new DefaultLogbackConfiguration(initializationContext, logFile).apply(configurator);
context.setPackagingDataEnabled(true);
}
```
```JAVA
@Override @Override
public void initialize(LoggingInitializationContext initializationContext, String configLocation, LogFile logFile) { public void initialize(LoggingInitializationContext initializationContext, String configLocation, LogFile logFile) {
LoggerContext loggerContext = getLoggerContext(); LoggerContext loggerContext = getLoggerContext();
@ -312,69 +305,66 @@ public static LoggingSystem get(ClassLoader classLoader) {
+ "' system property. Please use 'logging.config' instead."); + "' system property. Please use 'logging.config' instead.");
} }
} }
``` ```
标记`markAsInitialized`
```JAVA - 标记 `markAsInitialized`
private void markAsInitialized(LoggerContext loggerContext) {
loggerContext.putObject(LoggingSystem.class.getName(), new Object());
}
``` ```java
private void markAsInitialized(LoggerContext loggerContext) {
loggerContext.putObject(LoggingSystem.class.getName(), new Object());
}
```
此时日志初始化完成 此时日志初始化完成
### 默认配置文件 ### 默认配置文件
- `getStandardConfigLocations` 这个方法定义了默认配置文件有哪些 - `getStandardConfigLocations` 这个方法定义了默认配置文件有哪些
```java ```java
@Override @Override
protected String[] getStandardConfigLocations() { protected String[] getStandardConfigLocations() {
return new String[] { "logback-test.groovy", "logback-test.xml", "logback.groovy", "logback.xml" }; return new String[] { "logback-test.groovy", "logback-test.xml", "logback.groovy", "logback.xml" };
} }
```
```
- 切回`org.springframework.boot.logging.AbstractLoggingSystem#initializeWithConventions`方法 - 切回 `org.springframework.boot.logging.AbstractLoggingSystem#initializeWithConventions` 方法
- 添加依赖 - 添加依赖
```XML ```XML
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId> <artifactId>spring-boot-starter-logging</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
``` ```
- 添加配置文件 - 添加配置文件
![image-20200323161442058](../../images/SpringBoot/image-20200323161442058.png) ![image-20200323161442058](../../images/SpringBoot/image-20200323161442058.png)
![image-20200323161522570](../../images/SpringBoot/image-20200323161522570.png) ![image-20200323161522570](../../images/SpringBoot/image-20200323161522570.png)
- 此时配置文件地址出现了 - 此时配置文件地址出现了
```JAVA ```java
protected String getSelfInitializationConfig() { protected String getSelfInitializationConfig() {
// 寻找配置文件 // 寻找配置文件
return findConfig(getStandardConfigLocations()); return findConfig(getStandardConfigLocations());
} }
```
``` ```java
```JAVA
@Override @Override
protected String[] getStandardConfigLocations() { protected String[] getStandardConfigLocations() {
return new String[] { "logback-test.groovy", "logback-test.xml", "logback.groovy", "logback.xml" }; return new String[] { "logback-test.groovy", "logback-test.xml", "logback.groovy", "logback.xml" };
} }
``` ```
```JAVA ```java
private String findConfig(String[] locations) { private String findConfig(String[] locations) {
for (String location : locations) { for (String location : locations) {
ClassPathResource resource = new ClassPathResource(location, this.classLoader); ClassPathResource resource = new ClassPathResource(location, this.classLoader);
@ -384,73 +374,71 @@ public static LoggingSystem get(ClassLoader classLoader) {
} }
return null; return null;
} }
```
``` - 此时自定义配置文件如何获取的已经明了。
- 此时自定义配置文件如何获取的已经明了
#### reinitialize #### reinitialize
```JAVA ```java
@Override @Override
protected void reinitialize(LoggingInitializationContext initializationContext) { protected void reinitialize(LoggingInitializationContext initializationContext) {
// 日志上下文重新设置 // 日志上下文重新设置
getLoggerContext().reset(); getLoggerContext().reset();
getLoggerContext().getStatusManager().clear(); getLoggerContext().getStatusManager().clear();
// 加载配置文件 // 加载配置文件
loadConfiguration(initializationContext, getSelfInitializationConfig(), null); loadConfiguration(initializationContext, getSelfInitializationConfig(), null);
} }
``` ```
```JAVA ```java
@Override @Override
protected void loadConfiguration(LoggingInitializationContext initializationContext, String location, protected void loadConfiguration(LoggingInitializationContext initializationContext, String location,
LogFile logFile) { LogFile logFile) {
// 父类方法 // 父类方法
super.loadConfiguration(initializationContext, location, logFile); super.loadConfiguration(initializationContext, location, logFile);
// 获取上下文 // 获取上下文
LoggerContext loggerContext = getLoggerContext(); LoggerContext loggerContext = getLoggerContext();
// 停止并且重启 // 停止并且重启
stopAndReset(loggerContext); stopAndReset(loggerContext);
try { try {
// 配置文件加载 // 配置文件加载
configureByResourceUrl(initializationContext, loggerContext, ResourceUtils.getURL(location)); configureByResourceUrl(initializationContext, loggerContext, ResourceUtils.getURL(location));
} }
catch (Exception ex) { catch (Exception ex) {
throw new IllegalStateException("Could not initialize Logback logging from " + location, ex); throw new IllegalStateException("Could not initialize Logback logging from " + location, ex);
} }
List<Status> statuses = loggerContext.getStatusManager().getCopyOfStatusList(); List<Status> statuses = loggerContext.getStatusManager().getCopyOfStatusList();
StringBuilder errors = new StringBuilder(); StringBuilder errors = new StringBuilder();
for (Status status : statuses) { for (Status status : statuses) {
if (status.getLevel() == Status.ERROR) { if (status.getLevel() == Status.ERROR) {
errors.append((errors.length() > 0) ? String.format("%n") : ""); errors.append((errors.length() > 0) ? String.format("%n") : "");
errors.append(status.toString()); errors.append(status.toString());
}
}
if (errors.length() > 0) {
throw new IllegalStateException(String.format("Logback configuration error detected: %n%s", errors));
} }
} }
if (errors.length() > 0) {
throw new IllegalStateException(String.format("Logback configuration error detected: %n%s", errors));
}
}
``` ```
```java ```java
private void configureByResourceUrl(LoggingInitializationContext initializationContext, LoggerContext loggerContext, private void configureByResourceUrl(LoggingInitializationContext initializationContext, LoggerContext loggerContext,
URL url) throws JoranException { URL url) throws JoranException {
if (url.toString().endsWith("xml")) { if (url.toString().endsWith("xml")) {
// logback 日志操作 // logback 日志操作
JoranConfigurator configurator = new SpringBootJoranConfigurator(initializationContext); JoranConfigurator configurator = new SpringBootJoranConfigurator(initializationContext);
// 设置上下文 // 设置上下文
configurator.setContext(loggerContext); configurator.setContext(loggerContext);
// 执行配置 // 执行配置
configurator.doConfigure(url); configurator.doConfigure(url);
} }
else { else {
new ContextInitializer(loggerContext).configureByResource(url); new ContextInitializer(loggerContext).configureByResource(url);
}
} }
}
``` ```
- 执行配置属于 logback 操作源码不在此进行分析 执行配置属于 logback 操作源码不在此进行分析

Loading…
Cancel
Save