Search code examples
logback

Retrieve Log's Thread in Logback Filter


Using ch.qos.logback:logback-core:1.2.3 I've added TurboFilter to the LoggerContext sniffing for all the logs that go through the loggers:

loggerContext.addTurboFilter(filter);

But I can't find a way to figure out the log Thread. It actually doesn't seem to be passed in to the TurboFilter function:

public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {
}

Any suggestions how to get the whole info from the loggers including the Threads?


Solution

  • It seems it wasn't so difficult at all. I figured it out that the decide method is called on the same Thread where the log has occurred, so Thread.currentThread().getName() gives the information I need.