|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2021 the original author or authors. |
|
|
|
|
* Copyright 2002-2023 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. |
|
|
|
@ -28,6 +28,7 @@ import org.springframework.util.Assert;
@@ -28,6 +28,7 @@ import org.springframework.util.Assert;
|
|
|
|
|
* format string ({@link String#format}) in its {@link #toString()}. |
|
|
|
|
* |
|
|
|
|
* @author Juergen Hoeller |
|
|
|
|
* @author Sebastien Deleuze |
|
|
|
|
* @since 5.2 |
|
|
|
|
* @see #of(Supplier) |
|
|
|
|
* @see #format(String, Object) |
|
|
|
@ -87,56 +88,57 @@ public abstract class LogMessage implements CharSequence {
@@ -87,56 +88,57 @@ public abstract class LogMessage implements CharSequence {
|
|
|
|
|
/** |
|
|
|
|
* 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 |
|
|
|
|
* @param arg1 the argument (can be {@code null}) |
|
|
|
|
* @see String#format(String, Object...) |
|
|
|
|
*/ |
|
|
|
|
public static LogMessage format(String format, Object arg1) { |
|
|
|
|
public static LogMessage format(String format, @Nullable Object arg1) { |
|
|
|
|
return new FormatMessage1(format, arg1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 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 |
|
|
|
|
* @param arg1 the first argument (can be {@code null}) |
|
|
|
|
* @param arg2 the second argument (can be {@code null}) |
|
|
|
|
* @see String#format(String, Object...) |
|
|
|
|
*/ |
|
|
|
|
public static LogMessage format(String format, Object arg1, Object arg2) { |
|
|
|
|
public static LogMessage format(String format, @Nullable Object arg1, @Nullable Object arg2) { |
|
|
|
|
return new FormatMessage2(format, arg1, arg2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 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 |
|
|
|
|
* @param arg3 the third argument |
|
|
|
|
* @param arg1 the first argument (can be {@code null}) |
|
|
|
|
* @param arg2 the second argument (can be {@code null}) |
|
|
|
|
* @param arg3 the third argument (can be {@code null}) |
|
|
|
|
* @see String#format(String, Object...) |
|
|
|
|
*/ |
|
|
|
|
public static LogMessage format(String format, Object arg1, Object arg2, Object arg3) { |
|
|
|
|
public static LogMessage format(String format, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3) { |
|
|
|
|
return new FormatMessage3(format, arg1, arg2, arg3); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 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 |
|
|
|
|
* @param arg3 the third argument |
|
|
|
|
* @param arg4 the fourth argument |
|
|
|
|
* @param arg1 the first argument (can be {@code null}) |
|
|
|
|
* @param arg2 the second argument (can be {@code null}) |
|
|
|
|
* @param arg3 the third argument (can be {@code null}) |
|
|
|
|
* @param arg4 the fourth argument (can be {@code null}) |
|
|
|
|
* @see String#format(String, Object...) |
|
|
|
|
*/ |
|
|
|
|
public static LogMessage format(String format, Object arg1, Object arg2, Object arg3, Object arg4) { |
|
|
|
|
public static LogMessage format(String format, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3, |
|
|
|
|
@Nullable Object arg4) { |
|
|
|
|
return new FormatMessage4(format, arg1, arg2, arg3, arg4); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 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) |
|
|
|
|
* @param args the varargs array (can be {@code null}, costly, prefer individual arguments) |
|
|
|
|
* @see String#format(String, Object...) |
|
|
|
|
*/ |
|
|
|
|
public static LogMessage format(String format, Object... args) { |
|
|
|
|
public static LogMessage format(String format, @Nullable Object... args) { |
|
|
|
|
return new FormatMessageX(format, args); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -170,9 +172,10 @@ public abstract class LogMessage implements CharSequence {
@@ -170,9 +172,10 @@ public abstract class LogMessage implements CharSequence {
|
|
|
|
|
|
|
|
|
|
private static final class FormatMessage1 extends FormatMessage { |
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
private final Object arg1; |
|
|
|
|
|
|
|
|
|
FormatMessage1(String format, Object arg1) { |
|
|
|
|
FormatMessage1(String format, @Nullable Object arg1) { |
|
|
|
|
super(format); |
|
|
|
|
this.arg1 = arg1; |
|
|
|
|
} |
|
|
|
@ -186,11 +189,13 @@ public abstract class LogMessage implements CharSequence {
@@ -186,11 +189,13 @@ public abstract class LogMessage implements CharSequence {
|
|
|
|
|
|
|
|
|
|
private static final class FormatMessage2 extends FormatMessage { |
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
private final Object arg1; |
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
private final Object arg2; |
|
|
|
|
|
|
|
|
|
FormatMessage2(String format, Object arg1, Object arg2) { |
|
|
|
|
FormatMessage2(String format, @Nullable Object arg1, @Nullable Object arg2) { |
|
|
|
|
super(format); |
|
|
|
|
this.arg1 = arg1; |
|
|
|
|
this.arg2 = arg2; |
|
|
|
@ -205,13 +210,16 @@ public abstract class LogMessage implements CharSequence {
@@ -205,13 +210,16 @@ public abstract class LogMessage implements CharSequence {
|
|
|
|
|
|
|
|
|
|
private static final class FormatMessage3 extends FormatMessage { |
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
private final Object arg1; |
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
private final Object arg2; |
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
private final Object arg3; |
|
|
|
|
|
|
|
|
|
FormatMessage3(String format, Object arg1, Object arg2, Object arg3) { |
|
|
|
|
FormatMessage3(String format, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3) { |
|
|
|
|
super(format); |
|
|
|
|
this.arg1 = arg1; |
|
|
|
|
this.arg2 = arg2; |
|
|
|
@ -227,15 +235,20 @@ public abstract class LogMessage implements CharSequence {
@@ -227,15 +235,20 @@ public abstract class LogMessage implements CharSequence {
|
|
|
|
|
|
|
|
|
|
private static final class FormatMessage4 extends FormatMessage { |
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
private final Object arg1; |
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
private final Object arg2; |
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
private final Object arg3; |
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
private final Object arg4; |
|
|
|
|
|
|
|
|
|
FormatMessage4(String format, Object arg1, Object arg2, Object arg3, Object arg4) { |
|
|
|
|
FormatMessage4(String format, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3, |
|
|
|
|
@Nullable Object arg4) { |
|
|
|
|
super(format); |
|
|
|
|
this.arg1 = arg1; |
|
|
|
|
this.arg2 = arg2; |
|
|
|
@ -252,9 +265,10 @@ public abstract class LogMessage implements CharSequence {
@@ -252,9 +265,10 @@ public abstract class LogMessage implements CharSequence {
|
|
|
|
|
|
|
|
|
|
private static final class FormatMessageX extends FormatMessage { |
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
private final Object[] args; |
|
|
|
|
|
|
|
|
|
FormatMessageX(String format, Object... args) { |
|
|
|
|
FormatMessageX(String format, @Nullable Object... args) { |
|
|
|
|
super(format); |
|
|
|
|
this.args = args; |
|
|
|
|
} |
|
|
|
|