Hello,

Several times I've been in a situation where in a given JVM I am trying to
run distinct jobs in separate threads, who themselves might spawn their own
threads.
In those situations I usually want the logging of each job in a separate
log file, and that has proven to be difficult.

Log4j2 has a routing appender that allows to create a separate appender for
each job given that you can provide a routing key that's unique for each
job. But what key to use for this?
I've been using a ThreadContext variable that I set at the level of the job
thread, and any child thread that I have control over.

But the problem is that I don't always have control over this. Sometimes
third party APIs let you feed a custom ThreadFactory, sometimes they don't.
When they don't, I can't set that ThreadContext variable and part of the
job logging will be misrouted to a different appender.

Is there a way to work around this so that there is 1 log file for each job
that would gather all the logging of the sub threads?

Thanks,
Benjamin

Reply via email to