1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.turbo;
15
16 import org.slf4j.Marker;
17 import org.slf4j.MarkerFactory;
18
19 import ch.qos.logback.classic.Level;
20 import ch.qos.logback.classic.Logger;
21 import ch.qos.logback.core.spi.FilterReply;
22
23
24
25
26
27 public class MarkerFilter extends MatchingFilter {
28
29 Marker markerToMatch;
30
31 @Override
32 public void start() {
33 if (markerToMatch != null) {
34 super.start();
35 } else {
36 addError("The marker property must be set for [" + getName() + "]");
37 }
38 }
39
40 @Override
41 public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {
42 if (!isStarted()) {
43 return FilterReply.NEUTRAL;
44 }
45
46 if (marker == null) {
47 return onMismatch;
48 }
49
50 if (marker.contains(markerToMatch)) {
51 return onMatch;
52 } else {
53 return onMismatch;
54 }
55 }
56
57
58
59
60
61
62 public void setMarker(String markerStr) {
63 if (markerStr != null) {
64 this.markerToMatch = MarkerFactory.getMarker(markerStr);
65 }
66 }
67 }