Class BaseMessageFormatter
- java.lang.Object
-
- io.spine.logging.flogger.parser.MessageBuilder<StringBuilder>
-
- io.spine.logging.flogger.backend.BaseMessageFormatter
-
- All Implemented Interfaces:
ParameterVisitor
public class BaseMessageFormatter extends MessageBuilder<StringBuilder> implements ParameterVisitor
The default formatter for log messages and arguments.This formatter can be overridden to modify the behaviour of the
ParameterVisitormethods, but this is not expected to be common. Most logger backends will only ever need to useappendFormattedMessage(LogData, StringBuilder).- See Also:
- Original Java code of Google Flogger
-
-
Field Summary
Fields Modifier and Type Field Description protected Object[]argsprotected StringBuilderout
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseMessageFormatter(TemplateContext context, Object[] args, StringBuilder out)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddParameterImpl(int termStart, int termEnd, Parameter param)Adds the specified parameter to the format instance currently being built.static StringBuilderappendFormattedMessage(LogData data, StringBuilder out)Appends the formatted log message of the given log data to the given buffer.StringBuilderbuildImpl()Returns the implementation specific result of parsing the current log message.voidvisit(Object value, FormatChar format, FormatOptions options)Visits a log message argument with formatting specified by%s,%detc...voidvisitDateTime(Object value, DateTimeFormat format, FormatOptions options)Visits a date/time log message argument with formatting specified by%tor similar.voidvisitMissing()Visits a missing argument.voidvisitNull()Visits a null argument.voidvisitPreformatted(Object value, String formatted)Visits a log message argument for which formatting has already occurred.-
Methods inherited from class io.spine.logging.flogger.parser.MessageBuilder
addParameter, build, getExpectedArgumentCount, getMessage, getParser
-
-
-
-
Field Detail
-
args
protected final Object[] args
-
out
protected final StringBuilder out
-
-
Constructor Detail
-
BaseMessageFormatter
protected BaseMessageFormatter(TemplateContext context, Object[] args, StringBuilder out)
-
-
Method Detail
-
appendFormattedMessage
@CanIgnoreReturnValue public static StringBuilder appendFormattedMessage(LogData data, StringBuilder out)
Appends the formatted log message of the given log data to the given buffer.Note that the
LogDataneed not have a template context or arguments, it might just have a literal argument, which will be appended without additional formatting.- Parameters:
data- the log data with the message to be appended.out- a buffer to append to.- Returns:
- the given buffer (for method chaining).
-
addParameterImpl
public void addParameterImpl(int termStart, int termEnd, Parameter param)Description copied from class:MessageBuilderAdds the specified parameter to the format instance currently being built. This method is to signify that the parsing of the next parameter is complete.Note that each successive call to this method during parsing will specify a disjoint ranges of characters from the log message and that each range will be higher that the previously specified one.
- Specified by:
addParameterImplin classMessageBuilder<StringBuilder>- Parameters:
termStart- the index of the first character in the log message string that was parsed to form the given parameter.termEnd- the index after the last character in the log message string that was parsed to form the given parameter.param- a parameter representing the format specified by the substring of the log message in the range[termStart, termEnd).
-
buildImpl
public StringBuilder buildImpl()
Description copied from class:MessageBuilderReturns the implementation specific result of parsing the current log message.- Specified by:
buildImplin classMessageBuilder<StringBuilder>
-
visit
public void visit(Object value, FormatChar format, FormatOptions options)
Description copied from interface:ParameterVisitorVisits a log message argument with formatting specified by%s,%detc...Note that this method may still visit arguments which represent date/time values if the format is not explicit (e.g.
log("time=%s", dateTime)).- Specified by:
visitin interfaceParameterVisitor- Parameters:
value- the non-null log message argument.format- the printf format specifier.options- formatting options.
-
visitDateTime
public void visitDateTime(Object value, DateTimeFormat format, FormatOptions options)
Description copied from interface:ParameterVisitorVisits a date/time log message argument with formatting specified by%tor similar.Note that because this method is called based on the specified format (and not the argument type) it may visit arguments whose type is not a known date/time value. This is necessary to permit new date/time types to be supported by different logging backends (e.g. JodaTime).
- Specified by:
visitDateTimein interfaceParameterVisitor- Parameters:
value- the non-null log message argument.format- the date/time format specifier.options- formatting options.
-
visitPreformatted
public void visitPreformatted(Object value, String formatted)
Description copied from interface:ParameterVisitorVisits a log message argument for which formatting has already occurred. This method is only invoked when non-printf message formatting is used (e.g. brace style formatting).This method is intended for use by
Parameterimplementations which describe formatting rules which cannot by represented by eitherFormatCharorDateTimeFormat. This method discards formatting and type information, and the visitor implementation may choose to reexamine the type of the original argument if doing structural logging.- Specified by:
visitPreformattedin interfaceParameterVisitor- Parameters:
value- the original non-null log message argument.formatted- the formatted representation of the argument
-
visitMissing
public void visitMissing()
Description copied from interface:ParameterVisitorVisits a missing argument. This method is called when there is no corresponding value for the parameter's argument index.- Specified by:
visitMissingin interfaceParameterVisitor
-
visitNull
public void visitNull()
Description copied from interface:ParameterVisitorVisits a null argument.- Specified by:
visitNullin interfaceParameterVisitor
-
-