Skip to content
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

Copy of #8238 #8263

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions runtime/src/main/java/io/micronaut/logging/LoggingSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ public interface LoggingSystem {
*/
void setLogLevel(@NotBlank String name, @NotNull LogLevel level);

/**
* Refreshes Logging System with the goal of cleaning its internal caches
*
*/
default void refresh() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ final class PropertiesLoggingLevelsConfigurer implements ApplicationEventListene
public PropertiesLoggingLevelsConfigurer(Environment environment, List<LoggingSystem> loggingSystems) {
this.environment = environment;
this.loggingSystems = loggingSystems;
initLogging();
configureLogLevels();
}

Expand All @@ -74,9 +75,12 @@ public PropertiesLoggingLevelsConfigurer(Environment environment, List<LoggingSy
*/
@Override
public void onApplicationEvent(RefreshEvent event) {
if (event.getSource().keySet().stream().anyMatch(key -> key.startsWith(LOGGER_LEVELS_PROPERTY_PREFIX))) {
configureLogLevels();
}
initLogging();
configureLogLevels();
}

private void initLogging() {
this.loggingSystems.forEach(LoggingSystem::refresh);
}

private void configureLogLevels() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public void setLogLevel(String name, LogLevel level) {
getLoggerContext().getLogger(name).setLevel(toLevel(level));
}

@Override
public void refresh() {
getLoggerContext().reset();
}

/**
* @return The logback {@link LoggerContext}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,25 @@ logger:
'foo.bar3' | Level.INFO
}

void 'logging refresh is properly called on application start'() {
given:
ApplicationContext context = ApplicationContext.builder()
.build()

def loggingSystem = context.getBean(LoggingSystem.class)
def spy = Spy(loggingSystem)

when:
SystemLambda.withEnvironmentVariable("LOGGER_LEVELS_FOO_BAR3", "INFO")
.execute(() -> {
context.start()
})

then:
1 * spy.refresh()

cleanup:
context.close()
}

}