Package net.morimekta.providence.util
Class LogFormatter
- java.lang.Object
-
- net.morimekta.providence.util.LogFormatter
-
public class LogFormatter extends java.lang.Object
LogFormatter 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 interface
LogFormatter.FieldHandler
Handler 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 PMessage<Message,Field>,Field extends PField>
java.lang.Stringformat(Message message)
Format message to a string.<Message extends PMessage<Message,Field>,Field extends PField>
voidformatTo(java.io.OutputStream out, 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 PMessage<Message,Field>,Field extends PField> void formatTo(java.io.OutputStream out, Message message)
Format message and write to the output stream.- Type Parameters:
Message
- The message type.Field
- The field type.- Parameters:
out
- The output stream to write to.message
- The message to be written.
-
-