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.appenders.mail;
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   * 1024 events regardless of event level.
23   */
24  public class CounterBasedEvaluator extends ContextAwareBase implements EventEvaluator {
25  
26      static int LIMIT = 1024;
27      int counter = 0;
28      String name;
29      boolean started;
30  
31      public boolean evaluate(Object event) throws NullPointerException, EvaluationException {
32          counter++;
33  
34          if (counter == LIMIT) {
35              counter = 0;
36  
37              return true;
38          } else {
39              return false;
40          }
41      }
42  
43      public String getName() {
44          return name;
45      }
46  
47      public void setName(String name) {
48          this.name = name;
49      }
50  
51      public boolean isStarted() {
52          return started;
53      }
54  
55      public void start() {
56          started = true;
57      }
58  
59      public void stop() {
60          started = false;
61      }
62  }