Skip to content

Decoder needs parsers for Logger name, thread name etc #4

@michaeldjcox

Description

@michaeldjcox

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions