View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
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  }