All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ch.qos.logback.classic.boolex.ExceptionMatchEvaluator Maven / Gradle / Ivy

The newest version!
/*
 * Logback: the reliable, generic, fast and flexible logging framework.
 * Copyright (C) 1999-2024, QOS.ch. All rights reserved.
 *
 * This program and the accompanying materials are dual-licensed under
 * either the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation
 *
 *   or (per the licensee's choosing)
 *
 * under the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation.
 */

package ch.qos.logback.classic.boolex;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.IThrowableProxy;
import ch.qos.logback.core.boolex.EvaluationException;
import ch.qos.logback.core.boolex.EventEvaluatorBase;

/**
 * A simple {@link ch.qos.logback.core.boolex.EventEvaluator} that checks whether the
 * logging event being evaluated has a throwable of the same class as specified by the
 * {@link #exceptionClass} parameter.
 *
 * 

Here is a

*
 *  <configuration>
 *     <import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
 *     <import class="ch.qos.logback.core.filter.EvaluatorFilter"/>
 *     <import class="ch.qos.logback.classic.boolex.ExceptionMatchEvaluator"/>
 *     <import class="ch.qos.logback.core.ConsoleAppender"/>
 *
 *     <appender name="CONSOLE" class="ConsoleAppender">
 *         <filter class="EvaluatorFilter">
 *             <evaluator class="ExceptionMatchEvaluator">
 *                 <exceptionClass>java.lang.RuntimeException</exceptionClass>
 *             </evaluator>
 *             <OnMismatch>DENY</OnMismatch>
 *             <OnMatch>NEUTRAL</OnMatch>
 *         </filter>
 *
 *         <encoder class="PatternLayoutEncoder">
 *             <pattern>%-4relative [%thread] %-5level %logger -%kvp -%msg%n</pattern>
 *         </encoder>
 *     </appender>
 *
 *     <root level="INFO">
 *         <appender-ref ref="CONSOLE"/>
 *     </root>
 * </configuration>
 *
 *
 * 
*/ public class ExceptionMatchEvaluator extends EventEvaluatorBase { String exceptionClass; private boolean start = false; public void start() { if (exceptionClass == null) { addError("The exceptionClass must be set"); return; } start = true; } public void stop() { start = false; } public boolean isStarted() { return start; } @Override public boolean evaluate(ILoggingEvent event) throws NullPointerException, EvaluationException { IThrowableProxy throwableProxy = event.getThrowableProxy(); if (throwableProxy == null) { return false; } return throwableProxy.getClassName().equalsIgnoreCase(exceptionClass); } public String getExceptionClass() { return exceptionClass; } public void setExceptionClass(String exceptionClass) { this.exceptionClass = exceptionClass; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy