View Javadoc

1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2011, 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.boolex;
15  
16  import java.util.ArrayList;
17  import java.util.List;
18  
19  import org.slf4j.Marker;
20  
21  import ch.qos.logback.classic.spi.ILoggingEvent;
22  import ch.qos.logback.core.boolex.EvaluationException;
23  import ch.qos.logback.core.boolex.EventEvaluatorBase;
24  
25  /**
26   * Evaluates to true when the logging event passed as parameter contains one of
27   * the user-specified markers.
28   * 
29   * @author Ceki Gülcü
30   */
31  public class OnMarkerEvaluator extends EventEvaluatorBase<ILoggingEvent> {
32  
33    List<String> markerList = new ArrayList<String>();
34  
35    public void addMarker(String markerStr) {
36      markerList.add(markerStr);
37    }
38  
39    /**
40     * Return true if event passed as parameter contains one of the specified
41     * user-markers.
42     */
43    public boolean evaluate(ILoggingEvent event) throws NullPointerException,
44        EvaluationException {
45  
46      Marker eventsMarker = event.getMarker();
47      if (eventsMarker == null) {
48        return false;
49      }
50  
51      for (String markerStr : markerList) {
52        if (eventsMarker.contains(markerStr)) {
53          return true;
54        }
55      }
56      return false;
57    }
58  }