|
1 | 1 | /* |
2 | | - * Copyright 2012-2020 the original author or authors. |
| 2 | + * Copyright 2012-2021 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
25 | 25 | import java.util.LinkedHashMap; |
26 | 26 | import java.util.List; |
27 | 27 | import java.util.Map; |
28 | | -import java.util.logging.Level; |
29 | 28 |
|
30 | 29 | import com.fasterxml.jackson.databind.ObjectMapper; |
31 | 30 | import org.apache.commons.logging.Log; |
|
34 | 33 | import org.apache.logging.log4j.Logger; |
35 | 34 | import org.apache.logging.log4j.core.LoggerContext; |
36 | 35 | import org.apache.logging.log4j.core.config.Configuration; |
| 36 | +import org.apache.logging.log4j.core.config.LoggerConfig; |
37 | 37 | import org.apache.logging.log4j.core.config.Reconfigurable; |
38 | 38 | import org.junit.jupiter.api.AfterEach; |
39 | 39 | import org.junit.jupiter.api.BeforeEach; |
@@ -241,7 +241,7 @@ void loggingThatUsesJulIsCaptured(CapturedOutput output) { |
241 | 241 | this.loggingSystem.beforeInitialize(); |
242 | 242 | this.loggingSystem.initialize(null, null, null); |
243 | 243 | java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger(getClass().getName()); |
244 | | - julLogger.setLevel(Level.INFO); |
| 244 | + julLogger.setLevel(java.util.logging.Level.INFO); |
245 | 245 | julLogger.severe("Hello world"); |
246 | 246 | assertThat(output).contains("Hello world"); |
247 | 247 | } |
@@ -338,6 +338,38 @@ void initializationIsOnlyPerformedOnceUntilCleanedUp() { |
338 | 338 | verify(listener, times(4)).propertyChange(any(PropertyChangeEvent.class)); |
339 | 339 | } |
340 | 340 |
|
| 341 | + @Test |
| 342 | + void getLoggingConfigurationWithResetLevelReturnsNull() { |
| 343 | + this.loggingSystem.beforeInitialize(); |
| 344 | + this.loggingSystem.initialize(null, null, null); |
| 345 | + this.loggingSystem.setLogLevel("com.example", LogLevel.WARN); |
| 346 | + this.loggingSystem.setLogLevel("com.example.test", LogLevel.DEBUG); |
| 347 | + LoggerConfiguration configuration = this.loggingSystem.getLoggerConfiguration("com.example.test"); |
| 348 | + assertThat(configuration) |
| 349 | + .isEqualTo(new LoggerConfiguration("com.example.test", LogLevel.DEBUG, LogLevel.DEBUG)); |
| 350 | + this.loggingSystem.setLogLevel("com.example.test", null); |
| 351 | + LoggerConfiguration updatedConfiguration = this.loggingSystem.getLoggerConfiguration("com.example.test"); |
| 352 | + assertThat(updatedConfiguration).isNull(); |
| 353 | + } |
| 354 | + |
| 355 | + @Test |
| 356 | + void getLoggingConfigurationWithResetLevelWhenAlreadyConfiguredReturnsParentConfiguredLevel() { |
| 357 | + LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false); |
| 358 | + this.loggingSystem.beforeInitialize(); |
| 359 | + this.loggingSystem.initialize(null, null, null); |
| 360 | + loggerContext.getConfiguration().addLogger("com.example.test", |
| 361 | + new LoggerConfig("com.example.test", org.apache.logging.log4j.Level.INFO, false)); |
| 362 | + this.loggingSystem.setLogLevel("com.example", LogLevel.WARN); |
| 363 | + this.loggingSystem.setLogLevel("com.example.test", LogLevel.DEBUG); |
| 364 | + LoggerConfiguration configuration = this.loggingSystem.getLoggerConfiguration("com.example.test"); |
| 365 | + assertThat(configuration) |
| 366 | + .isEqualTo(new LoggerConfiguration("com.example.test", LogLevel.DEBUG, LogLevel.DEBUG)); |
| 367 | + this.loggingSystem.setLogLevel("com.example.test", null); |
| 368 | + LoggerConfiguration updatedConfiguration = this.loggingSystem.getLoggerConfiguration("com.example.test"); |
| 369 | + assertThat(updatedConfiguration) |
| 370 | + .isEqualTo(new LoggerConfiguration("com.example.test", LogLevel.WARN, LogLevel.WARN)); |
| 371 | + } |
| 372 | + |
341 | 373 | private String getRelativeClasspathLocation(String fileName) { |
342 | 374 | String defaultPath = ClassUtils.getPackageName(getClass()); |
343 | 375 | defaultPath = defaultPath.replace('.', '/'); |
|
0 commit comments