001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package chapters.appenders.mail; 015 016import ch.qos.logback.core.boolex.EvaluationException; 017import ch.qos.logback.core.boolex.EventEvaluator; 018import ch.qos.logback.core.spi.ContextAwareBase; 019 020/** 021 * A simple EventEvaluator implementation that triggers email transmission after 022 * 1024 events regardless of event level. 023 */ 024public class CounterBasedEvaluator extends ContextAwareBase implements EventEvaluator { 025 026 static int LIMIT = 1024; 027 int counter = 0; 028 String name; 029 boolean started; 030 031 public boolean evaluate(Object event) throws NullPointerException, EvaluationException { 032 counter++; 033 034 if (counter == LIMIT) { 035 counter = 0; 036 037 return true; 038 } else { 039 return false; 040 } 041 } 042 043 public String getName() { 044 return name; 045 } 046 047 public void setName(String name) { 048 this.name = name; 049 } 050 051 public boolean isStarted() { 052 return started; 053 } 054 055 public void start() { 056 started = true; 057 } 058 059 public void stop() { 060 started = false; 061 } 062}