Class MessageUtils


  • public final class MessageUtils
    extends Object
    Static utilities for classes wishing to implement their own log message formatting. None of the methods here are required in a formatter, but they should help solve problems common to log message formatting.
    See Also:
    Original Java code of Google Flogger
    • Method Detail

      • appendLogSite

        @CanIgnoreReturnValue
        public static boolean appendLogSite​(FloggerLogSite logSite,
                                            StringBuilder out)
        Appends log-site information in the default format, including a trailing space.
        Parameters:
        logSite - the log site to be appended (ingored if FloggerLogSite.INVALID).
        out - the destination buffer.
        Returns:
        whether the log-site was appended.
      • safeToString

        public static String safeToString​(Object value)
        Returns a string representation of the user supplied value accounting for any possible runtime exceptions. This code will never fail, but may return a synthetic error string if exceptions were thrown.
        Parameters:
        value - the value to be formatted.
        Returns:
        a best-effort string representation of the given value, even if exceptions were thrown.
      • safeFormatTo

        public static void safeFormatTo​(Formattable value,
                                        StringBuilder out,
                                        FormatOptions options)
        Returns a string representation of the user supplied Formattable, accounting for any possible runtime exceptions.
        Parameters:
        value - the value to be formatted.
        out - the buffer into which to format it.
        options - the format options (extracted from a printf placeholder in the log message).