Package org.springframework.core.log
Class LogFormatUtils
- java.lang.Object
- org.springframework.core.log.LogFormatUtils
public abstract class LogFormatUtils extends Object
Utility methods for formatting and logging messages.Mainly for internal use within the framework with Apache Commons Logging, typically in the form of the
spring-jcl
bridge but also compatible with other Commons Logging bridges.- Since:
- 5.1
- Author:
- Rossen Stoyanchev, Juergen Hoeller
Constructor Summary
Constructors Constructor Description LogFormatUtils()
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
formatValue(Object value, boolean limitLength)
Format the given value viatoString()
, quoting it if it is aCharSequence
, and possibly truncating at 100 if limitLength is set to true.static void
traceDebug(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 Detail
LogFormatUtils
public LogFormatUtils()
Method Detail
formatValue
public static String formatValue(@Nullable Object value, boolean limitLength)
Format the given value viatoString()
, quoting it if it is aCharSequence
, and possibly truncating at 100 if limitLength is set to true.- Parameters:
value
- the value to formatlimitLength
- whether to truncate large formatted values (over 100)- Returns:
- the formatted value
traceDebug
public static void traceDebug(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()