View Javadoc

1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2009, 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 chapter6;
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,
31        String format, Object[] params, Throwable t) {
32      
33      if (!isStarted()) {
34        return FilterReply.NEUTRAL;
35      }
36  
37      if ((markerToAccept.equals(marker))) {
38        return FilterReply.ACCEPT;
39      } else {
40        return FilterReply.NEUTRAL;
41      }
42    }
43  
44    public String getMarker() {
45      return marker;
46    }
47  
48    public void setMarker(String markerStr) {
49      this.marker = markerStr;
50    }
51  
52    @Override
53    public void start() {
54      if (marker != null && marker.trim().length() > 0) {
55        markerToAccept = MarkerFactory.getMarker(marker);
56        super.start(); 
57      }
58    }
59  }