Class 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.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <Message extends PMessage<Message,​Field>,​Field extends PField>
      java.lang.String
      format​(Message message)
      Format message to a string.
      <Message extends PMessage<Message,​Field>,​Field extends PField>
      void
      formatTo​(java.io.OutputStream out, Message message)
      Format message and write to the output stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.
      • format

        public <Message extends PMessage<Message,​Field>,​Field extends PField> java.lang.String format​(Message message)
        Format message to a string.
        Type Parameters:
        Message - The message type.
        Field - The field type.
        Parameters:
        message - The message to be written.
        Returns:
        The formatted message.