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