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 ch.qos.logback.classic.spi;
15  
16  import java.util.concurrent.CopyOnWriteArrayList;
17  
18  import org.slf4j.Marker;
19  
20  import ch.qos.logback.classic.Level;
21  import ch.qos.logback.classic.Logger;
22  import ch.qos.logback.classic.turbo.TurboFilter;
23  import ch.qos.logback.core.spi.FilterReply;
24  
25  /**
26   * Implementation of TurboFilterAttachable.
27   * 
28   * @author Ceki Gülcü
29   */
30  final public class TurboFilterList extends CopyOnWriteArrayList<TurboFilter> {
31  
32      private static final long serialVersionUID = 1L;
33  
34      /**
35       * Loop through the filters in the chain. As soon as a filter decides on ACCEPT
36       * or DENY, then that value is returned. If all of the filters return NEUTRAL,
37       * then NEUTRAL is returned.
38       */
39      public FilterReply getTurboFilterChainDecision(final Marker marker, final Logger logger, final Level level,
40              final String format, final Object[] params, final Throwable t) {
41  
42          final int size = size();
43          // if (size == 0) {
44          // return FilterReply.NEUTRAL;
45          // }
46          if (size == 1) {
47              try {
48                  TurboFilter tf = get(0);
49                  return tf.decide(marker, logger, level, format, params, t);
50              } catch (IndexOutOfBoundsException iobe) {
51                  return FilterReply.NEUTRAL;
52              }
53          }
54  
55          Object[] tfa = toArray();
56          final int len = tfa.length;
57          for (int i = 0; i < len; i++) {
58              // for (TurboFilter tf : this) {
59              final TurboFilter tf = (TurboFilter) tfa[i];
60              final FilterReply r = tf.decide(marker, logger, level, format, params, t);
61              if (r == FilterReply.DENY || r == FilterReply.ACCEPT) {
62                  return r;
63              }
64          }
65          return FilterReply.NEUTRAL;
66      }
67  
68      // public boolean remove(TurboFilter turboFilter) {
69      // return tfList.remove(turboFilter);
70      // }
71      //
72      // public TurboFilter remove(int index) {
73      // return tfList.remove(index);
74      // }
75      //
76      // final public int size() {
77      // return tfList.size();
78      // }
79  
80  }