Class LogFormatUtils
java.lang.Object
org.springframework.core.log.LogFormatUtils
Utility methods for formatting and logging messages.
Mainly for internal use within the framework with Apache Commons Logging.
- Since:
- 5.1
- Author:
- Rossen Stoyanchev, Juergen Hoeller
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatValue(@Nullable Object value, boolean limitLength) Convenience variant offormatValue(Object, int, boolean)that limits the length of a log message to 100 characters and also replaces newline and control characters iflimitLengthis set to "true".static StringformatValue(@Nullable Object value, int maxLength, boolean replaceNewlinesAndControlCharacters) Format the given value viatoString(), quoting it if it is aCharSequence, truncating at the specifiedmaxLength, and compacting it into a single line whenreplaceNewLinesis set.static voidtraceDebug(org.apache.commons.logging.Log logger, Function<Boolean, String> messageFactory) Use this to log a message with different levels of detail (or different messages) at TRACE vs DEBUG log levels.
-
Constructor Details
-
LogFormatUtils
public LogFormatUtils()
-
-
Method Details
-
formatValue
Convenience variant offormatValue(Object, int, boolean)that limits the length of a log message to 100 characters and also replaces newline and control characters iflimitLengthis set to "true".- Parameters:
value- the value to formatlimitLength- whether to truncate the value at a length of 100- Returns:
- the formatted value
-
formatValue
public static String formatValue(@Nullable Object value, int maxLength, boolean replaceNewlinesAndControlCharacters) Format the given value viatoString(), quoting it if it is aCharSequence, truncating at the specifiedmaxLength, and compacting it into a single line whenreplaceNewLinesis set.- Parameters:
value- the value to be formattedmaxLength- the max length, after which to truncate, or -1 for unlimitedreplaceNewlinesAndControlCharacters- whether to replace newline and control characters with placeholders- Returns:
- the formatted value
-
traceDebug
public static void traceDebug(org.apache.commons.logging.Log logger, Function<Boolean, String> messageFactory) Use this to log a message with different levels of detail (or different messages) at TRACE vs DEBUG log levels. Effectively, a substitute for:if (logger.isDebugEnabled()) { String str = logger.isTraceEnabled() ? "..." : "..."; if (logger.isTraceEnabled()) { logger.trace(str); } else { logger.debug(str); } }- Parameters:
logger- the logger to use to log the messagemessageFactory- function that accepts a boolean set to the value ofLog.isTraceEnabled()
-