Class PatternFlattener

  • All Implemented Interfaces:
    Flattener, Flattener2
    Direct Known Subclasses:
    ClassicFlattener

    public class PatternFlattener
    extends java.lang.Object
    implements Flattener, Flattener2
    Flatten the log using the format specified by pattern.

    Supported parameters:

    Parameter Represents
    {d} Date in default date format "yyyy-MM-dd HH:mm:ss.SSS"
    {d format} Date in specific date format
    {l} Short name of log level. e.g: V/D/I
    {L} Long name of log level. e.g: VERBOSE/DEBUG/INFO
    {t} Tag of log
    {m} Message of log

    Imagine there is a log, with LogLevel.DEBUG level, "my_tag" tag and "Simple message" message, the flattened log would be as below.

    Pattern Flattened log
    {d} {l}/{t}: {m} 2016-11-30 13:00:00.000 D/my_tag: Simple message
    {d yyyy-MM-dd HH:mm:ss.SSS} {l}/{t}: {m} 2016-11-30 13:00:00.000 D/my_tag: Simple message
    {d yyyy/MM/dd HH:mm:ss} {l}|{t}: {m} 2016/11/30 13:00:00 D|my_tag: Simple message
    {d yy/MM/dd HH:mm:ss} {l}|{t}: {m} 16/11/30 13:00:00 D|my_tag: Simple message
    {d MM/dd HH:mm} {l}-{t}-{m} 11/30 13:00 D-my_tag-Simple message
    Since:
    1.3.0
    • Constructor Summary

      Constructors 
      Constructor Description
      PatternFlattener​(java.lang.String pattern)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.CharSequence flatten​(int logLevel, java.lang.String tag, java.lang.String message)
      Flatten the log.
      java.lang.CharSequence flatten​(long timeMillis, int logLevel, java.lang.String tag, java.lang.String message)
      Flatten the log.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PatternFlattener

        public PatternFlattener​(java.lang.String pattern)
        Constructor.
        Parameters:
        pattern - the format pattern to flatten the log
    • Method Detail

      • flatten

        public java.lang.CharSequence flatten​(int logLevel,
                                              java.lang.String tag,
                                              java.lang.String message)
        Description copied from interface: Flattener
        Flatten the log.
        Specified by:
        flatten in interface Flattener
        Parameters:
        logLevel - the level of log
        tag - the tag of log
        message - the message of log
        Returns:
        the formatted final log Charsequence
      • flatten

        public java.lang.CharSequence flatten​(long timeMillis,
                                              int logLevel,
                                              java.lang.String tag,
                                              java.lang.String message)
        Description copied from interface: Flattener2
        Flatten the log.
        Specified by:
        flatten in interface Flattener2
        Parameters:
        timeMillis - the time milliseconds of log
        logLevel - the level of log
        tag - the tag of log
        message - the message of log
        Returns:
        the formatted final log Charsequence