diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DebugLogbackConfigurator.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DebugLogbackConfigurator.java index e98296ef63..3e05b60400 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DebugLogbackConfigurator.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DebugLogbackConfigurator.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ package org.springframework.boot.logging.logback; +import java.util.function.Supplier; + import ch.qos.logback.classic.Level; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.spi.ILoggingEvent; @@ -38,10 +40,10 @@ class DebugLogbackConfigurator extends LogbackConfigurator { } @Override - @SuppressWarnings("rawtypes") - public void conversionRule(String conversionWord, Class converterClass) { + > void conversionRule(String conversionWord, Class converterClass, + Supplier converterSupplier) { info("Adding conversion rule of type '" + converterClass.getName() + "' for word '" + conversionWord + "'"); - super.conversionRule(conversionWord, converterClass); + super.conversionRule(conversionWord, converterClass, converterSupplier); } @Override diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DefaultLogbackConfiguration.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DefaultLogbackConfiguration.java index c136bd93a7..6be56b1dd7 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DefaultLogbackConfiguration.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DefaultLogbackConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -99,11 +99,12 @@ class DefaultLogbackConfiguration { private void defaults(LogbackConfigurator config) { deprecatedDefaults(config); - config.conversionRule("clr", ColorConverter.class); - config.conversionRule("correlationId", CorrelationIdConverter.class); - config.conversionRule("esb", EnclosedInSquareBracketsConverter.class); - config.conversionRule("wex", WhitespaceThrowableProxyConverter.class); - config.conversionRule("wEx", ExtendedWhitespaceThrowableProxyConverter.class); + config.conversionRule("clr", ColorConverter.class, ColorConverter::new); + config.conversionRule("correlationId", CorrelationIdConverter.class, CorrelationIdConverter::new); + config.conversionRule("esb", EnclosedInSquareBracketsConverter.class, EnclosedInSquareBracketsConverter::new); + config.conversionRule("wex", WhitespaceThrowableProxyConverter.class, WhitespaceThrowableProxyConverter::new); + config.conversionRule("wEx", ExtendedWhitespaceThrowableProxyConverter.class, + ExtendedWhitespaceThrowableProxyConverter::new); putProperty(config, "CONSOLE_LOG_PATTERN", CONSOLE_LOG_PATTERN); putProperty(config, "CONSOLE_LOG_CHARSET", "${CONSOLE_LOG_CHARSET:-" + DEFAULT_CHARSET + "}"); putProperty(config, "CONSOLE_LOG_THRESHOLD", "${CONSOLE_LOG_THRESHOLD:-TRACE}"); @@ -124,7 +125,7 @@ class DefaultLogbackConfiguration { @SuppressWarnings("removal") private void deprecatedDefaults(LogbackConfigurator config) { - config.conversionRule("applicationName", ApplicationNameConverter.class); + config.conversionRule("applicationName", ApplicationNameConverter.class, ApplicationNameConverter::new); } void putProperty(LogbackConfigurator config, String name, String val) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackConfigurator.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackConfigurator.java index a64f1ce1f5..9c491c4c74 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackConfigurator.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackConfigurator.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.springframework.boot.logging.logback; import java.util.HashMap; import java.util.Map; import java.util.concurrent.locks.ReentrantLock; +import java.util.function.Supplier; import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; @@ -54,17 +55,18 @@ class LogbackConfigurator { return this.context.getConfigurationLock(); } - @SuppressWarnings({ "rawtypes", "unchecked" }) - void conversionRule(String conversionWord, Class converterClass) { + @SuppressWarnings("unchecked") + > void conversionRule(String conversionWord, Class converterClass, + Supplier converterSupplier) { Assert.hasLength(conversionWord, "Conversion word must not be empty"); - Assert.notNull(converterClass, "Converter class must not be null"); - Map registry = (Map) this.context - .getObject(CoreConstants.PATTERN_RULE_REGISTRY); + Assert.notNull(converterSupplier, "Converter supplier must not be null"); + Map> registry = (Map>) this.context + .getObject(CoreConstants.PATTERN_RULE_REGISTRY_FOR_SUPPLIERS); if (registry == null) { registry = new HashMap<>(); - this.context.putObject(CoreConstants.PATTERN_RULE_REGISTRY, registry); + this.context.putObject(CoreConstants.PATTERN_RULE_REGISTRY_FOR_SUPPLIERS, registry); } - registry.put(conversionWord, converterClass.getName()); + registry.put(conversionWord, converterSupplier); } void appender(String name, Appender appender) { diff --git a/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml b/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml index 73e2c20b4c..c97ca1df3a 100644 --- a/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml +++ b/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml @@ -8,7 +8,7 @@ Default logback configuration provided for import - +