
On 23.09.2011 10:40, Lars Fischer wrote:
Hello Ceki,
thank you for your answer!
2011/9/22 Ceki Gülcü<ceki@qos.ch>:
1) For data which stays relatively stable during the scope of (service) request, MDC is the way to go.
What about data which could change, lets say for every log event? (e.g. two alternating docIds) Reading the documentation, the MDC is no good choice for such often changing data.
If the alternation occurs in the same thread very frequently, then you are correct, MDC is not a good choice. However, if alternation frequency is say every 10 or 20 logging events, then MDC should be OK.
Can I put this data into the Object[] of the Logger methods?
Yes, you can do that. For example, if docId data is typed as DocID, you can write: DocId docId1 = new DocId("1"); DocId docId2 = new DocId("2"); logger.info("starting processing", docId1); logger.info("starting processing", docId2); // now with two parameters logger.info("adding a paragraph {}", paragraph, docId1); logger.info("end of processing", docId1); logger.info("end of processing", docId2); Please let me know if you run into trouble with this approach. It should work though. If you wish to output the data using PatternLayout, you will need to write a custom converter. Writing a custom converter is documented at [1]. Again, in case you encounter any difficulty, just ask for help here. [1] http://logback.qos.ch/manual/layouts.html#customConversionSpecifier -- Ceki http://twitter.com/ceki