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 ch.qos.logback.classic.boolex;
015
016import java.util.ArrayList;
017import java.util.List;
018
019import org.slf4j.Marker;
020
021import ch.qos.logback.classic.spi.ILoggingEvent;
022import ch.qos.logback.core.boolex.EvaluationException;
023import ch.qos.logback.core.boolex.EventEvaluatorBase;
024
025/**
026 * Evaluates to true when the logging event passed as parameter contains one of
027 * the user-specified markers.
028 * 
029 * @author Ceki Gülcü
030 */
031public class OnMarkerEvaluator extends EventEvaluatorBase<ILoggingEvent> {
032
033    List<String> markerList = new ArrayList<String>();
034
035    public void addMarker(String markerStr) {
036        markerList.add(markerStr);
037    }
038
039    /**
040     * Return true if event passed as parameter contains one of the specified
041     * user-markers.
042     */
043    public boolean evaluate(ILoggingEvent event) throws NullPointerException, EvaluationException {
044
045        Marker eventsMarker = event.getMarker();
046        if (eventsMarker == null) {
047            return false;
048        }
049
050        for (String markerStr : markerList) {
051            if (eventsMarker.contains(markerStr)) {
052                return true;
053            }
054        }
055        return false;
056    }
057}