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.net;
15  
16  import ch.qos.logback.core.boolex.EvaluationException;
17  import ch.qos.logback.core.boolex.EventEvaluator;
18  import ch.qos.logback.core.spi.ContextAwareBase;
19  
20  /**
21   * A simple EventEvaluator implementation that triggers email transmission after
22   * a given number of events occur, regardless of event level.
23   * 
24   * <p>By default, the limit is 1024.
25   */
26  public class CounterBasedEvaluator extends ContextAwareBase implements EventEvaluator<Object> {
27  
28      static int DEFAULT_LIMIT = 1024;
29      int limit = DEFAULT_LIMIT;
30      int counter = 0;
31      String name;
32      boolean started;
33  
34      public boolean evaluate(Object event) throws NullPointerException, EvaluationException {
35          counter++;
36  
37          if (counter == limit) {
38              counter = 0;
39              return true;
40          } else {
41              return false;
42          }
43      }
44  
45      public String getName() {
46          return name;
47      }
48  
49      public void setName(String name) {
50          this.name = name;
51      }
52  
53      public boolean isStarted() {
54          return started;
55      }
56  
57      public void start() {
58          started = true;
59      }
60  
61      public void stop() {
62          started = false;
63      }
64  
65      public int getLimit() {
66          return limit;
67      }
68  
69      public void setLimit(int limit) {
70          this.limit = limit;
71      }
72  
73  }