Class MessageUtils
- java.lang.Object
-
- com.google.common.flogger.backend.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.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanappendLogSite(LogSite logSite, StringBuilder out)Appends log-site information in the default format, including a trailing space.static voidsafeFormatTo(Formattable value, StringBuilder out, FormatOptions options)Returns a string representation of the user suppliedFormattable, accounting for any possible runtime exceptions.static StringsafeToString(Object value)Returns a string representation of the user supplied value accounting for any possible runtime exceptions.
-
-
-
Method Detail
-
appendLogSite
@CanIgnoreReturnValue public static boolean appendLogSite(LogSite logSite, StringBuilder out)
Appends log-site information in the default format, including a trailing space.- Parameters:
logSite- the log site to be appended (ingored ifLogSite.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 suppliedFormattable, 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).
-
-