accessing multiple values in MDC with siftingappender or gsiftingappender

£可爱£侵袭症+ 提交于 2019-12-11 11:59:53

问题


I have a siftingappender 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?


回答1:


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.



来源:https://stackoverflow.com/questions/6187512/accessing-multiple-values-in-mdc-with-siftingappender-or-gsiftingappender

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!