Package net.morimekta.providence.logging
Class LogFormatter
- java.lang.Object
-
- net.morimekta.providence.logging.LogFormatter
-
public class LogFormatter extends java.lang.ObjectLogFormatter is a formatter (one-way serialization) similar to the PrettySerializer, except it supports adding FieldHandlers to modify in. Note that the LogFormatter is not a serializer, as there is no guarantee the result can be parsed back at all.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceLogFormatter.FieldHandlerHandler for a single field in a message.
-
Constructor Summary
Constructors Constructor Description LogFormatter(boolean pretty, java.util.Collection<LogFormatter.FieldHandler> fieldHandlers)Create a log formatter.LogFormatter(boolean pretty, LogFormatter.FieldHandler... fieldHandlers)Create a log formatter.LogFormatter(LogFormatter.FieldHandler... fieldHandlers)Create a log formatter with compact format.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <Message extends net.morimekta.providence.PMessage<Message>>
java.lang.Stringformat(net.morimekta.providence.PMessageOrBuilder<Message> message)Format message to a string.<Message extends net.morimekta.providence.PMessage<Message>>
voidformatTo(java.io.OutputStream out, net.morimekta.providence.PMessageOrBuilder<Message> message)Format message and write to the output stream.
-
-
-
Constructor Detail
-
LogFormatter
public LogFormatter(LogFormatter.FieldHandler... fieldHandlers)
Create a log formatter with compact format.- Parameters:
fieldHandlers- Field handlers to specify formatted values of specific fields.
-
LogFormatter
public LogFormatter(boolean pretty, LogFormatter.FieldHandler... fieldHandlers)Create a log formatter.- Parameters:
pretty- If true will add lines, line indentation and extra spaces.fieldHandlers- Field handlers to specify formatted values of specific fields.
-
LogFormatter
public LogFormatter(boolean pretty, java.util.Collection<LogFormatter.FieldHandler> fieldHandlers)Create a log formatter.- Parameters:
pretty- If true will add lines, line indentation and extra spaces.fieldHandlers- Field handlers to specify formatted values of specific fields.
-
-
Method Detail
-
formatTo
public <Message extends net.morimekta.providence.PMessage<Message>> void formatTo(java.io.OutputStream out, net.morimekta.providence.PMessageOrBuilder<Message> message)Format message and write to the output stream.- Type Parameters:
Message- The message type.- Parameters:
out- The output stream to write to.message- The message to be written.
-
format
public <Message extends net.morimekta.providence.PMessage<Message>> java.lang.String format(net.morimekta.providence.PMessageOrBuilder<Message> message)
Format message to a string.- Type Parameters:
Message- The message type.- Parameters:
message- The message to be written.- Returns:
- The formatted message.
-
-