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.spi.ILoggingEvent;
17 import ch.qos.logback.core.sift.AbstractDiscriminator;
18
19
20
21
22
23
24
25
26
27
28
29 public class ContextBasedDiscriminator extends AbstractDiscriminator<ILoggingEvent> {
30
31 private static final String KEY = "contextName";
32 private String defaultValue;
33
34
35
36
37 public String getDiscriminatingValue(ILoggingEvent event) {
38 String contextName = event.getLoggerContextVO().getName();
39
40 if (contextName == null) {
41 return defaultValue;
42 } else {
43 return contextName;
44 }
45 }
46
47 public String getKey() {
48 return KEY;
49 }
50
51 public void setKey(String key) {
52 throw new UnsupportedOperationException("Key cannot be set. Using fixed key " + KEY);
53 }
54
55
56
57
58
59 public String getDefaultValue() {
60 return defaultValue;
61 }
62
63
64
65
66
67
68
69 public void setDefaultValue(String defaultValue) {
70 this.defaultValue = defaultValue;
71 }
72 }