开发者

accessing multiple values in MDC with siftingappender or gsiftingappender

开发者 https://www.devze.com 2023-03-09 22:49 出处:网络
I have a s开发者_StackOverflowiftingappender that i use for a key in mdc to customize the file appenders. The problem is i cannot access multiple values from the configuration.

I have a s开发者_StackOverflowiftingappender that i use for a key in mdc to customize the file appenders. The problem is i cannot access multiple values from the configuration.

Is there a way to access 2 or more keys that exists in MDC?


I had the same problem, and looking at the class it appeared it wasn't possible to use two discriminator keys. The solution I used was then to set a property containing the combination of this values at the beginning of the "session" :

String value1 = "a variable";
String username = "the username";
MDC.put("myDiscriminatingValue", value1 + username);

and then you just have to put "myDiscriminatingValue" in logback.xml as a discriminating value.

A more elegant way to achieve it would be to implement your own Discriminator class instead of MDCBasedDicriminator.

0

精彩评论

暂无评论...
验证码 换一张
取 消