diff --git a/spring-core/src/main/java/org/springframework/core/log/LogAccessor.java b/spring-core/src/main/java/org/springframework/core/log/LogAccessor.java index acae717962..168f7f2c7e 100644 --- a/spring-core/src/main/java/org/springframework/core/log/LogAccessor.java +++ b/spring-core/src/main/java/org/springframework/core/log/LogAccessor.java @@ -180,7 +180,7 @@ public class LogAccessor { * @param messageSupplier a lazy supplier for the message to log */ public void fatal(Supplier messageSupplier) { - this.log.fatal(LogMessage.lazy(messageSupplier)); + this.log.fatal(LogMessage.of(messageSupplier)); } /** @@ -189,7 +189,7 @@ public class LogAccessor { * @param messageSupplier a lazy supplier for the message to log */ public void fatal(Throwable cause, Supplier messageSupplier) { - this.log.fatal(LogMessage.lazy(messageSupplier), cause); + this.log.fatal(LogMessage.of(messageSupplier), cause); } /** @@ -197,7 +197,7 @@ public class LogAccessor { * @param messageSupplier a lazy supplier for the message to log */ public void error(Supplier messageSupplier) { - this.log.error(LogMessage.lazy(messageSupplier)); + this.log.error(LogMessage.of(messageSupplier)); } /** @@ -206,7 +206,7 @@ public class LogAccessor { * @param messageSupplier a lazy supplier for the message to log */ public void error(Throwable cause, Supplier messageSupplier) { - this.log.error(LogMessage.lazy(messageSupplier), cause); + this.log.error(LogMessage.of(messageSupplier), cause); } /** @@ -214,7 +214,7 @@ public class LogAccessor { * @param messageSupplier a lazy supplier for the message to log */ public void warn(Supplier messageSupplier) { - this.log.warn(LogMessage.lazy(messageSupplier)); + this.log.warn(LogMessage.of(messageSupplier)); } /** @@ -223,7 +223,7 @@ public class LogAccessor { * @param messageSupplier a lazy supplier for the message to log */ public void warn(Throwable cause, Supplier messageSupplier) { - this.log.warn(LogMessage.lazy(messageSupplier), cause); + this.log.warn(LogMessage.of(messageSupplier), cause); } /** @@ -231,7 +231,7 @@ public class LogAccessor { * @param messageSupplier a lazy supplier for the message to log */ public void info(Supplier messageSupplier) { - this.log.info(LogMessage.lazy(messageSupplier)); + this.log.info(LogMessage.of(messageSupplier)); } /** @@ -240,7 +240,7 @@ public class LogAccessor { * @param messageSupplier a lazy supplier for the message to log */ public void info(Throwable cause, Supplier messageSupplier) { - this.log.info(LogMessage.lazy(messageSupplier), cause); + this.log.info(LogMessage.of(messageSupplier), cause); } /** @@ -248,7 +248,7 @@ public class LogAccessor { * @param messageSupplier a lazy supplier for the message to log */ public void debug(Supplier messageSupplier) { - this.log.debug(LogMessage.lazy(messageSupplier)); + this.log.debug(LogMessage.of(messageSupplier)); } /** @@ -257,7 +257,7 @@ public class LogAccessor { * @param messageSupplier a lazy supplier for the message to log */ public void debug(Throwable cause, Supplier messageSupplier) { - this.log.debug(LogMessage.lazy(messageSupplier), cause); + this.log.debug(LogMessage.of(messageSupplier), cause); } /** @@ -265,7 +265,7 @@ public class LogAccessor { * @param messageSupplier a lazy supplier for the message to log */ public void trace(Supplier messageSupplier) { - this.log.trace(LogMessage.lazy(messageSupplier)); + this.log.trace(LogMessage.of(messageSupplier)); } /** @@ -274,7 +274,7 @@ public class LogAccessor { * @param messageSupplier a lazy supplier for the message to log */ public void trace(Throwable cause, Supplier messageSupplier) { - this.log.trace(LogMessage.lazy(messageSupplier), cause); + this.log.trace(LogMessage.of(messageSupplier), cause); } } diff --git a/spring-core/src/main/java/org/springframework/core/log/LogMessage.java b/spring-core/src/main/java/org/springframework/core/log/LogMessage.java index 9c0a199fc8..298ebfff31 100644 --- a/spring-core/src/main/java/org/springframework/core/log/LogMessage.java +++ b/spring-core/src/main/java/org/springframework/core/log/LogMessage.java @@ -29,7 +29,7 @@ import org.springframework.util.Assert; * * @author Juergen Hoeller * @since 5.2 - * @see #lazy(Supplier) + * @see #of(Supplier) * @see #format(String, Object) * @see #format(String, Object...) * @see org.apache.commons.logging.Log#fatal(Object) @@ -76,16 +76,16 @@ public abstract class LogMessage implements CharSequence { /** - * Build a lazy resolution message from the given supplier. + * Build a lazily resolving message from the given supplier. * @param supplier the supplier (typically bound to a Java 8 lambda expression) * @see #toString() */ - public static LogMessage lazy(Supplier supplier) { - return new LazyMessage(supplier); + public static LogMessage of(Supplier supplier) { + return new SupplierMessage(supplier); } /** - * Build a formatted message from the given format string and argument. + * Build a lazily formatted message from the given format string and argument. * @param format the format string (following {@link String#format} rules) * @param arg1 the argument * @see String#format(String, Object...) @@ -95,7 +95,7 @@ public abstract class LogMessage implements CharSequence { } /** - * Build a formatted message from the given format string and arguments. + * Build a lazily formatted message from the given format string and arguments. * @param format the format string (following {@link String#format} rules) * @param arg1 the first argument * @param arg2 the second argument @@ -106,7 +106,7 @@ public abstract class LogMessage implements CharSequence { } /** - * Build a formatted message from the given format string and arguments. + * Build a lazily formatted message from the given format string and arguments. * @param format the format string (following {@link String#format} rules) * @param arg1 the first argument * @param arg2 the second argument @@ -118,7 +118,7 @@ public abstract class LogMessage implements CharSequence { } /** - * Build a formatted message from the given format string and arguments. + * Build a lazily formatted message from the given format string and arguments. * @param format the format string (following {@link String#format} rules) * @param arg1 the first argument * @param arg2 the second argument @@ -131,7 +131,7 @@ public abstract class LogMessage implements CharSequence { } /** - * Build a formatted message from the given format string and varargs. + * Build a lazily formatted message from the given format string and varargs. * @param format the format string (following {@link String#format} rules) * @param args the varargs array (costly, prefer individual arguments) * @see String#format(String, Object...) @@ -141,11 +141,11 @@ public abstract class LogMessage implements CharSequence { } - private static final class LazyMessage extends LogMessage { + private static final class SupplierMessage extends LogMessage { private Supplier supplier; - LazyMessage(Supplier supplier) { + SupplierMessage(Supplier supplier) { Assert.notNull(supplier, "Supplier must not be null"); this.supplier = supplier; } diff --git a/spring-core/src/test/java/org/springframework/core/log/LogSupportTests.java b/spring-core/src/test/java/org/springframework/core/log/LogSupportTests.java index a181751d4e..bbd7097f4e 100644 --- a/spring-core/src/test/java/org/springframework/core/log/LogSupportTests.java +++ b/spring-core/src/test/java/org/springframework/core/log/LogSupportTests.java @@ -28,7 +28,7 @@ public class LogSupportTests { @Test public void testLogMessageWithSupplier() { - LogMessage msg = LogMessage.lazy(() -> new StringBuilder("a").append(" b")); + LogMessage msg = LogMessage.of(() -> new StringBuilder("a").append(" b")); assertEquals("a b", msg.toString()); assertSame(msg.toString(), msg.toString()); }