logback print full MDC in appender
Asked Answered
D

2

17

In an appender in a logback.xml is it possible to do any operation like iterating over an MDC, printing the entire MDC, etc.? The easiest way I can think to do this is basically via java/groovy code (which I haven't researched how to do yet), was wondering if there's a shorthand.

Dogwatch answered 6/12, 2012 at 17:44 Comment(0)
C
29

If you are using the patternlayout using %mdc should work. E.g:

"%d [%thread] %-5level %logger{36} - %msg %mdc%n"

Cacoepy answered 3/2, 2016 at 11:34 Comment(0)
B
-3

Logback contains a failry extensive page on MDC here.

Personally I've never dealt with it, but all the code examples from the manual show it accessed via Java code, in fact after the 3rd paragraph it begins introducing sample code for accessing the MDC which leads me to beleive there is no shorthand for it.

You can access the Javadoc for the MDC classes here.

Bacciferous answered 6/12, 2012 at 19:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.