So, this is what I'm after:
It looks like log4j has similar contexts available:
- http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/MDC.html
- http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/NDC.html
SLF4J has support here:
Pregunta
I have a thread of operation which I would like to be logging like so:
id = tied to a "session" which is known at runtime (not 100%, but mostly a session is everything on a sepecific thread)
KEY = value tied to a particular package, probably can just make a different formater pattern with each package/key
12:12:12,123 [INFO] [id] KEY > Something informative
12:12:13,123 [INFO] [id] KEY > Something informative
12:12:14,123 [ERROR] [id] KEY > OMG IT BROKE!
12:12:15,123 [INFO] [id] KEY > Something informative
I already have SLF4J logging, but I'm getting the classic style:
19:18:41,491 INFO [com.package.package.Class] (ThreadName) Something Informative
19:18:42,491 INFO [com.package.package.Class] (ThreadName) Something Informative
I realize I can create a different format for the classes I'm after in the log4j/logback/whatever properites/xml file; however, I have no idea how to inject that [id] value which is only known at runtime.
Is there a way to do this "properly" with SLF4J or do I need to create my own Log4J Logger instance at runtime and couple my code to log4j (which I've tried very hard not to do).
Solución
So, this is what I'm after:
It looks like log4j has similar contexts available:
SLF4J has support here: