I have a multithreaded application where every thread operates different objects with names i.e.:
process-1
process-2
process-3
Currently the pattern looks like this:
[%thread] - %msg %n
And I want to achieve something like this:
[%thread] %processName - %msg %n
Where processName
is specified in the object.
My goal is to add those names to generated logs, so I would be able to grep them very easily when I will need to review history. I'm logging already thread name, but this is not enough for me.
I have started with MDC, however, turns out it keeps the stored name between all threads. In the best scenario, it uses that name for all logs, in worst, the property is empty.
How can I achieve this thread-safe logging with or without MDC?