1
2
3
4
5
6
7
8
9
10
11
12
13
14 package chapters.filters;
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.classic.turbo.TurboFilter;
22 import ch.qos.logback.core.spi.FilterReply;
23
24 public class SampleTurboFilter extends TurboFilter {
25
26 String marker;
27 Marker markerToAccept;
28
29 @Override
30 public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {
31
32 if (!isStarted()) {
33 return FilterReply.NEUTRAL;
34 }
35
36 if ((markerToAccept.equals(marker))) {
37 return FilterReply.ACCEPT;
38 } else {
39 return FilterReply.NEUTRAL;
40 }
41 }
42
43 public String getMarker() {
44 return marker;
45 }
46
47 public void setMarker(String markerStr) {
48 this.marker = markerStr;
49 }
50
51 @Override
52 public void start() {
53 if (marker != null && marker.trim().length() > 0) {
54 markerToAccept = MarkerFactory.getMarker(marker);
55 super.start();
56 }
57 }
58 }