-
Notifications
You must be signed in to change notification settings - Fork 40.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resetting the log level of a Log4j2 Logger wrongly flags its LoggerConfiguration as explicitly configured #24298
Comments
@ST-DDT thanks for the report. FTR, there is no need to specify a That's not a problem with the actuator as it merely get that information from the |
The problem can be reproduced by the following test: @Test
void getLoggingConfigurationWithResetLevelShouldReturnLoggerWithNullConfiguredLevel() {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(null, null, null);
this.loggingSystem.setLogLevel("com.example", LogLevel.WARN);
this.loggingSystem.setLogLevel("com.example.test", LogLevel.DEBUG);
LoggerConfiguration configuration = this.loggingSystem.getLoggerConfiguration("com.example.test");
assertThat(configuration).isEqualTo(new LoggerConfiguration("com.example.test", LogLevel.DEBUG, LogLevel.DEBUG));
this.loggingSystem.setLogLevel("com.example.test", null);
LoggerConfiguration updatedConfiguration = this.loggingSystem.getLoggerConfiguration("com.example.test");
assertThat(updatedConfiguration).isEqualTo(new LoggerConfiguration("com.example.test", null, LogLevel.WARN));
} |
Log4J2 |
Update `Log4J2LoggingSystem` so that call to `setLevel` with a `null` level with remove the logger if it was previously configured by a `LoggingSystem` call. To track which loggers have been configured by us, and which have been configure directly by the user a custom `LoggerConfig` subclass is used. We'll only remove `LevelSetLoggerConfig` classes, for any others we'll call `setLevel()` on the config. Prior to this commit, it was impossible to set then reset a logger level using the actuator endpoint. This is because Log4J doesn't provide a way to get the actual configured level. If the `setLevel(null)` has been applied, then `getLevel()` will return the value of the parent logger or a default value of `ERROR`. Closes spring-projectsgh-24298
Update `Log4J2LoggingSystem` so that call to `setLevel` with a `null` level with remove the logger if it was previously configured by a `LoggingSystem` call. To track which loggers have been configured by us, and which have been configure directly by the user, a custom `LoggerConfig` subclass is used. We'll only remove `LevelSetLoggerConfig` classes, for any others we'll call `setLevel(null)` on the config. Prior to this commit, it was impossible to set then reset a logger level using the actuator endpoint. This is because Log4J doesn't provide a way to get the actual configured level. If the `setLevel(null)` has been applied, then `getLevel()` will return the value of the parent logger or a default value of `ERROR`. Closes spring-projectsgh-24298
I've had a go at fixing this one in https://github.com/philwebb/spring-boot/tree/gh-24298. The commit message describes the idea behind the fix. I'm not confident enough to merge it without a review. |
I did review that commit back then and I seem to remember that |
Spring-Boot: v2.3.5.RELEASE
Log4J2: 2.13.3 (spring-managed)
As you can see the last two jsons display
de
as configured, but the value (even for the configured flag) is inherited fromROOT
.The text was updated successfully, but these errors were encountered: