Wednesday, 7 August 2013

Pluggable appenders per dynamic logging category?

Pluggable appenders per dynamic logging category?

I am using SLF4J and Log4J back-end.
I have stand-alone Java service, which takes "tasks" from queue and
executes the tasks in separate threads (Akka Actors, if that matters). I
want to send log messages to per-task log files (so every task starts to
log into it's own unique log file).
My requirements are:
implicitly pass task ID with log message
choose file to log by that ID
remove the ID when task ends, so no subsequent tasks can log to wrong file
by accident
So far it looks like I have to create my own log appender, which will
"recognize" task by some criteria (this is a big question, since I don't
see how to pass task ID to logger easily, and can not rely on ThreadLocal
because some tasks may start thread pools/fork-join, so it would be
complex to inherit thread context)
Do you know any existing logging implementation which might work for me?
May be some extensions to Log4J?

No comments:

Post a Comment