1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.sift;
15
16 import ch.qos.logback.classic.LoggerContext;
17 import ch.qos.logback.classic.selector.ContextSelector;
18 import ch.qos.logback.classic.spi.ILoggingEvent;
19 import ch.qos.logback.classic.util.ContextSelectorStaticBinder;
20 import ch.qos.logback.core.sift.AbstractDiscriminator;
21
22
23
24
25
26
27
28
29
30
31
32 public class JNDIBasedContextDiscriminator extends AbstractDiscriminator<ILoggingEvent> {
33
34 private static final String KEY = "contextName";
35 private String defaultValue;
36
37
38
39
40 public String getDiscriminatingValue(ILoggingEvent event) {
41 ContextSelector selector = ContextSelectorStaticBinder.getSingleton().getContextSelector();
42
43 if (selector == null) {
44 return defaultValue;
45 }
46
47 LoggerContext lc = selector.getLoggerContext();
48 if (lc == null) {
49 return defaultValue;
50 }
51
52 return lc.getName();
53 }
54
55 public String getKey() {
56 return KEY;
57 }
58
59 public void setKey(String key) {
60 throw new UnsupportedOperationException("Key cannot be set. Using fixed key " + KEY);
61 }
62
63
64
65
66
67 public String getDefaultValue() {
68 return defaultValue;
69 }
70
71
72
73
74
75
76
77 public void setDefaultValue(String defaultValue) {
78 this.defaultValue = defaultValue;
79 }
80 }