public abstract class LogFormatUtils extends Object
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.
Constructor and Description |
---|
LogFormatUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
formatValue(Object value,
boolean limitLength)
Convenience variant of
formatValue(Object, int, boolean) that
limits the length of a log message to 100 characters and also replaces
newline and control characters if limitLength is set to "true". |
static String |
formatValue(Object value,
int maxLength,
boolean replaceNewlinesAndControlCharacters)
Format the given value via
toString() , quoting it if it is a
CharSequence , truncating at the specified maxLength , and
compacting it into a single line when replaceNewLines is set. |
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.
|
public static String formatValue(@Nullable Object value, boolean limitLength)
formatValue(Object, int, boolean)
that
limits the length of a log message to 100 characters and also replaces
newline and control characters if limitLength
is set to "true".value
- the value to formatlimitLength
- whether to truncate the value at a length of 100public static String formatValue(@Nullable Object value, int maxLength, boolean replaceNewlinesAndControlCharacters)
toString()
, quoting it if it is a
CharSequence
, truncating at the specified maxLength
, and
compacting it into a single line when replaceNewLines
is set.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 placeholderspublic static void traceDebug(Log logger, Function<Boolean,String> messageFactory)
if (logger.isDebugEnabled()) { String str = logger.isTraceEnabled() ? "..." : "..."; if (logger.isTraceEnabled()) { logger.trace(str); } else { logger.debug(str); } }
logger
- the logger to use to log the messagemessageFactory
- function that accepts a boolean set to the value
of Log.isTraceEnabled()