Merge pull request #41885 from mches

* pr/41885:
  Polish "Upgrade to Logback 1.5.7"
  Upgrade to Logback 1.5.7

Closes gh-41885
This commit is contained in:
Stéphane Nicoll 2024-08-16 14:52:01 +02:00
commit 68d600e9da
6 changed files with 15 additions and 4 deletions

View File

@ -1121,7 +1121,7 @@ bom {
releaseNotes("https://github.com/apache/logging-log4j2/releases/tag/rel%2F{version}") releaseNotes("https://github.com/apache/logging-log4j2/releases/tag/rel%2F{version}")
} }
} }
library("Logback", "1.5.6") { library("Logback", "1.5.7") {
group("ch.qos.logback") { group("ch.qos.logback") {
modules = [ modules = [
"logback-classic", "logback-classic",

View File

@ -17,6 +17,7 @@
package org.springframework.boot.logging.logback; package org.springframework.boot.logging.logback;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.concurrent.locks.ReentrantLock;
import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.encoder.PatternLayoutEncoder; import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
@ -44,6 +45,7 @@ import org.springframework.boot.logging.LogFile;
* @author Robert Thornton * @author Robert Thornton
* @author Scott Frederick * @author Scott Frederick
* @author Jonatan Ivanov * @author Jonatan Ivanov
* @author Mark Chesney
*/ */
class DefaultLogbackConfiguration { class DefaultLogbackConfiguration {
@ -54,7 +56,9 @@ class DefaultLogbackConfiguration {
} }
void apply(LogbackConfigurator config) { void apply(LogbackConfigurator config) {
synchronized (config.getConfigurationLock()) { ReentrantLock lock = config.getConfigurationLock();
lock.lock();
try {
defaults(config); defaults(config);
Appender<ILoggingEvent> consoleAppender = consoleAppender(config); Appender<ILoggingEvent> consoleAppender = consoleAppender(config);
if (this.logFile != null) { if (this.logFile != null) {
@ -65,6 +69,9 @@ class DefaultLogbackConfiguration {
config.root(Level.INFO, consoleAppender); config.root(Level.INFO, consoleAppender);
} }
} }
finally {
lock.unlock();
}
} }
private void defaults(LogbackConfigurator config) { private void defaults(LogbackConfigurator config) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,6 +18,7 @@ package org.springframework.boot.logging.logback;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.Logger;
@ -49,7 +50,7 @@ class LogbackConfigurator {
return this.context; return this.context;
} }
Object getConfigurationLock() { ReentrantLock getConfigurationLock() {
return this.context.getConfigurationLock(); return this.context.getConfigurationLock();
} }

View File

@ -45,6 +45,7 @@ class LogbackLoggingSystemParallelInitializationTests {
void cleanUp() { void cleanUp() {
this.loggingSystem.cleanUp(); this.loggingSystem.cleanUp();
((LoggerContext) LoggerFactory.getILoggerFactory()).stop(); ((LoggerContext) LoggerFactory.getILoggerFactory()).stop();
((LoggerContext) LoggerFactory.getILoggerFactory()).reset();
} }
@Test @Test

View File

@ -128,6 +128,7 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
System.getProperties().keySet().retainAll(this.systemPropertyNames); System.getProperties().keySet().retainAll(this.systemPropertyNames);
this.loggingSystem.cleanUp(); this.loggingSystem.cleanUp();
((LoggerContext) LoggerFactory.getILoggerFactory()).stop(); ((LoggerContext) LoggerFactory.getILoggerFactory()).stop();
((LoggerContext) LoggerFactory.getILoggerFactory()).reset();
} }
@Test @Test

View File

@ -72,6 +72,7 @@ class SpringBootJoranConfiguratorTests {
@AfterEach @AfterEach
void reset() { void reset() {
this.context.stop(); this.context.stop();
this.context.reset();
new BasicConfigurator().configure((LoggerContext) LoggerFactory.getILoggerFactory()); new BasicConfigurator().configure((LoggerContext) LoggerFactory.getILoggerFactory());
} }