logback-decoder icon indicating copy to clipboard operation
logback-decoder copied to clipboard

Decoder needs parsers for Logger name, thread name etc

Open michaeldjcox opened this issue 11 years ago • 3 comments

In the Decoder class, common fields in log messages are not parsed into the LoggingEvent unless parsers are defined. e.g.

  @SuppressWarnings("serial")
  private static final Map<String, FieldCapturer<LoggingEvent>> DECODER_MAP =
    new HashMap<String, FieldCapturer<LoggingEvent>>() {{
      put(PatternNames.DATE, new DateParser());
      put(PatternNames.LEVEL, new LevelParser());
      put(PatternNames.MESSAGE, new MessageParser());

     //////////////////////////////////////////////////////////////////////////////////////////////////

      // NEED TO ADD PARSERS FOR COMMON FIELDS.....e.g.

      put(PatternNames.LOGGER_NAME, new LoggerNameParser()); 
      put(PatternNames.THREAD_NAME, new ThreadParser());

     // and probably others
     //////////////////////////////////////////////////////////////////////////////////////////////////

    }};

The LoggerNameParser and ThreadParser are faily simple. e.g.

public class ThreadParser implements FieldCapturer<LoggingEvent> {
  public static final Logger logger = LoggerFactory.getLogger(LevelParser.class);

  @Override
  public void captureField(LoggingEvent event, String fieldAsStr, PatternInfo info) {
    event.setThreadName(fieldAsStr.trim()); 
  }

}

trim() is needed - not sure why

Hope this helps

Michael

michaeldjcox avatar Jun 17 '13 12:06 michaeldjcox

Any hope of this being sorted?

michaeldjcox avatar Jul 19 '13 10:07 michaeldjcox

I'm a bit preoccupied, but I'll look into it this weekend.

tony19 avatar Jul 19 '13 13:07 tony19

I've added parsers for the following fields:

  • %caller
  • %class
  • %contextName
  • %line
  • %logger
  • %method
  • %thread

While unit tests exist for these fields, there might be some test cases I've missed. Feel free to create issues for them (and patches/pull-requests would be much appreciated).

The following fields are not [yet] parsed:

  • %BARE (not useful)
  • %exception, %xException, %rootException
  • %mdc
  • %property
  • %replace (not useful)
  • %relative
  • %marker
  • %newline (not useful)
  • (perhaps others)

tony19 avatar Jul 22 '13 02:07 tony19