org.springframework.core.log

Class LogFormatUtils

  • java.lang.Object
    • org.springframework.core.log.LogFormatUtils


  • public abstract class LogFormatUtils
    extends java.lang.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
    • Constructor Summary

      Constructors 
      Constructor and Description
      LogFormatUtils() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static java.lang.String formatValue(java.lang.Object value, boolean limitLength)
      Format the given value via toString(), quoting it if it is a CharSequence, and possibly truncating at 100 if limitLength is set to true.
      static void traceDebug(Log logger, java.util.function.Function<java.lang.Boolean,java.lang.String> messageFactory)
      Use this to log a message with different levels of detail (or different messages) at TRACE vs DEBUG log levels.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LogFormatUtils

        public LogFormatUtils()
    • Method Detail

      • formatValue

        public static java.lang.String formatValue(@Nullable
                                                   java.lang.Object value,
                                                   boolean limitLength)
        Format the given value via toString(), quoting it if it is a CharSequence, and possibly truncating at 100 if limitLength is set to true.
        Parameters:
        value - the value to format
        limitLength - whether to truncate large formatted values (over 100)
        Returns:
        the formatted value
        Since:
        5.1
      • traceDebug

        public static void traceDebug(Log logger,
                                      java.util.function.Function<java.lang.Boolean,java.lang.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 s = logger.isTraceEnabled() ? "..." : "...";
                if (logger.isTraceEnabled()) {
                        logger.trace(s);
                }
                else {
                        logger.debug(s);
                }
         }
         
        Parameters:
        logger - the logger to use to log the message
        messageFactory - function that accepts a boolean set to the value of Log.isTraceEnabled()