logback-gelf
logback-gelf copied to clipboard
Add ability to log thread ID in addition to thread name
Is your feature request related to a problem? Please describe.
Thread names in Java are not guaranteed unique, so it'd be useful to include thread ids as well. This would basically be analogous to logging %T
instead of/in addition to %t
in a Pattern Layout.
Describe the solution you'd like I'd like my GELF message to be able to include thread ID in addition to the thread name (presumably as an additional, separate field).
An alternative, more general solution would be allowing the definition of extra fields besides ShortPatternLayout
and FullPatternLayout
that can use Pattern Layouts in the same manner (static fields as currently implemented can only use Logback variable substitution, which as far as I can tell can't include something like the thread id).
Describe alternatives you've considered
Since ShortPatternLayout
and FullPatternLayout
are, indeed, Pattern Layouts, I could just include %T
in one of those, but this means I'd then have to parse the thread ID out of the message field later, which sort of feels like giving up a big benefit of using GELF.
Thanks for your request. An easy way how you could handle this right away:
de.siegmar.logbackgelf.GelfEncoder#addFieldMapper
...just add a custom mapper in order to send the thread id as a separate field to Graylog.
I just checked ch.qos.logback.classic.spi.ILoggingEvent
and couldn't find a way to obtain the thread ID. Also I read https://logback.qos.ch/manual/layouts.html#ClassicPatternLayout and couldn't find the mentioned %T
placeholder.
Even if there's a way to add the thread ID I'm not sure if it would help. According to java.lang.Thread#getId
:
The thread ID is unique and remains unchanged during its lifetime. When a thread is terminated, this thread ID may be reused.
Hence I'm closing this request. Let me know, if you have more information.