/**
 * 
 */
package com.ejie.ad74a.context.log;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.FilterReply;

/**
 * 
 * Filtro de logs de incidencias
 * 
 * @author JBHG
 *
 */
public class IncidencesLogFilter extends Filter<ILoggingEvent> {
	private boolean logIncidences = false;

	public void setLogIncidences(boolean logIncidences) {
		this.logIncidences = logIncidences;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ch.qos.logback.core.filter.Filter#decide(java.lang.Object)
	 */
	@Override
	public FilterReply decide(ILoggingEvent event) {
		if (logIncidences) {
			return (event.getLevel().levelInt >= Level.WARN_INT) ? FilterReply.ACCEPT : FilterReply.DENY;
		} else {
			return (event.getLevel().levelInt < Level.WARN_INT) ? FilterReply.ACCEPT : FilterReply.DENY;
		}
	}

}
