Simple Message Formatter
Helper class for formatting LogData as text. This class is useful for any logging backend which performs unstructured, text only, logging. Note however that it makes several assumptions regarding metadata and formatting, which may not apply to every text based logging backend.
This primarily exists to support both the JDK logging classes and text only Android backends. Code in here may be factored out as necessary to support other use cases in future.
If a text based logger backend is not performance critical, then it should just append the log message and metadata to a local buffer. For example:
MetadataProcessor metadata =
MetadataProcessor.forScopeAndLogSite(Platform.getInjectedMetadata(), logData.getMetadata());
StringBuilder buffer = new StringBuilder();
// Optional prefix goes here...
SimpleMessageFormatter.getDefaultFormatter().append(logData, metadata, buffer);
// Optional suffix goes here...
String message = buffer.toString();
If additional metadata keys, other than the cause are to be omitted, then getSimpleFormatterIgnoring can be used to obtain a static formatter, instead of using the default.
See also
Original Java code of Google Flogger
Functions
Log message [CONTEXT key="value" id=42 ]