logback-decoder
logback-decoder copied to clipboard
Decoder needs parsers for Logger name, thread name etc
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
Any hope of this being sorted?
I'm a bit preoccupied, but I'll look into it this weekend.
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)