类 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.

    从以下版本开始:
    5.1
    作者:
    Rossen Stoyanchev, Juergen Hoeller
    • 方法详细资料

      • formatValue

        public static String formatValue​(@Nullable
                                         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.
        参数:
        value - the value to format
        limitLength - whether to truncate large formatted values (over 100)
        返回:
        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);
           }
         }
         
        参数:
        logger - the logger to use to log the message
        messageFactory - function that accepts a boolean set to the value of Log.isTraceEnabled()