Package org.springframework.core.log
Class LogMessage
- java.lang.Object
- org.springframework.core.log.LogMessage
- All Implemented Interfaces:
CharSequence
public abstract class LogMessage extends Object implements CharSequence
A simple log message type for use with Commons Logging, allowing for convenient lazy resolution of a givenSupplier
instance (typically bound to a Java 8 lambda expression) or a printf-style format string (String.format(java.lang.String, java.lang.Object...)
) in itstoString()
.- Since:
- 5.2
- Author:
- Juergen Hoeller
- See Also:
of(Supplier)
,format(String, Object)
,format(String, Object...)
,Log.fatal(Object)
,Log.error(Object)
,Log.warn(Object)
,Log.info(Object)
,Log.debug(Object)
,Log.trace(Object)
Constructor Summary
Constructors Constructor Description LogMessage()
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description char
charAt(int index)
static LogMessage
format(String format, Object arg1)
Build a lazily formatted message from the given format string and argument.static LogMessage
format(String format, Object... args)
Build a lazily formatted message from the given format string and varargs.static LogMessage
format(String format, Object arg1, Object arg2)
Build a lazily formatted message from the given format string and arguments.static LogMessage
format(String format, Object arg1, Object arg2, Object arg3)
Build a lazily formatted message from the given format string and arguments.static LogMessage
format(String format, Object arg1, Object arg2, Object arg3, Object arg4)
Build a lazily formatted message from the given format string and arguments.int
length()
static LogMessage
of(Supplier<? extends CharSequence> supplier)
Build a lazily resolving message from the given supplier.CharSequence
subSequence(int start, int end)
String
toString()
This will be called by the logging provider, potentially once per log target (therefore locally caching the result here).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints
Constructor Detail
LogMessage
public LogMessage()
Method Detail
length
public int length()
- Specified by:
length
in interfaceCharSequence
charAt
public char charAt(int index)
- Specified by:
charAt
in interfaceCharSequence
subSequence
public CharSequence subSequence(int start, int end)
- Specified by:
subSequence
in interfaceCharSequence
toString
public String toString()
This will be called by the logging provider, potentially once per log target (therefore locally caching the result here).- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
of
public static LogMessage of(Supplier<? extends CharSequence> supplier)
Build a lazily resolving message from the given supplier.- Parameters:
supplier
- the supplier (typically bound to a Java 8 lambda expression)- See Also:
toString()
format
public static LogMessage format(String format, Object arg1)
Build a lazily formatted message from the given format string and argument.- Parameters:
format
- the format string (followingString.format(java.lang.String, java.lang.Object...)
rules)arg1
- the argument- See Also:
String.format(String, Object...)
format
public static LogMessage format(String format, Object arg1, Object arg2)
Build a lazily formatted message from the given format string and arguments.- Parameters:
format
- the format string (followingString.format(java.lang.String, java.lang.Object...)
rules)arg1
- the first argumentarg2
- the second argument- See Also:
String.format(String, Object...)
format
public static LogMessage format(String format, Object arg1, Object arg2, Object arg3)
Build a lazily formatted message from the given format string and arguments.- Parameters:
format
- the format string (followingString.format(java.lang.String, java.lang.Object...)
rules)arg1
- the first argumentarg2
- the second argumentarg3
- the third argument- See Also:
String.format(String, Object...)
format
public static LogMessage format(String format, Object arg1, Object arg2, Object arg3, Object arg4)
Build a lazily formatted message from the given format string and arguments.- Parameters:
format
- the format string (followingString.format(java.lang.String, java.lang.Object...)
rules)arg1
- the first argumentarg2
- the second argumentarg3
- the third argumentarg4
- the fourth argument- See Also:
String.format(String, Object...)
format
public static LogMessage format(String format, Object... args)
Build a lazily formatted message from the given format string and varargs.- Parameters:
format
- the format string (followingString.format(java.lang.String, java.lang.Object...)
rules)args
- the varargs array (costly, prefer individual arguments)- See Also:
String.format(String, Object...)