使用siftingappender或gsiftingappender访问MDC中的多个值 [英] accessing multiple values in MDC with siftingappender or gsiftingappender

查看:267
本文介绍了使用siftingappender或gsiftingappender访问MDC中的多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个siftingappender,用于在mdc中自定义文件附加器.问题是我无法从配置中访问多个值.

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.

是否可以访问MDC中存在的2个或更多密钥?

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);

然后您只需要在logback.xml中输入"myDiscriminationValue"作为区别值.

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

一种更优雅的实现方法是实现自己的Discriminator类,而不是MDCBasedDicriminator.

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

这篇关于使用siftingappender或gsiftingappender访问MDC中的多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆