View Javadoc

1   package chapter6;
2   
3   import org.slf4j.Marker;
4   import org.slf4j.MarkerFactory;
5   
6   import ch.qos.logback.classic.Level;
7   import ch.qos.logback.classic.Logger;
8   import ch.qos.logback.classic.turbo.TurboFilter;
9   import ch.qos.logback.core.spi.FilterReply;
10  
11  public class SampleTurboFilter extends TurboFilter {
12  
13    String marker;
14    Marker markerToAccept;
15  
16    @Override
17    public FilterReply decide(Marker marker, Logger logger, Level level,
18        String format, Object[] params, Throwable t) {
19      
20      if (!isStarted()) {
21        return FilterReply.NEUTRAL;
22      }
23  
24      if ((markerToAccept.equals(marker))) {
25        return FilterReply.ACCEPT;
26      } else {
27        return FilterReply.NEUTRAL;
28      }
29    }
30  
31    public String getMarker() {
32      return marker;
33    }
34  
35    public void setMarker(String markerStr) {
36      this.marker = markerStr;
37    }
38  
39    @Override
40    public void start() {
41      if (marker != null && marker.trim().length() > 0) {
42        markerToAccept = MarkerFactory.getMarker(marker);
43        super.start(); 
44      }
45    }
46  }