001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006package org.fcrepo.http.commons.exceptionhandlers;
007
008import org.slf4j.Logger;
009
010/**
011 * @author barmintor
012 * @since 6/28/16
013 */
014public interface ExceptionDebugLogging {
015    /**
016     * Log a Throwable at the DEBUG level, log the stacktrace at the TRACE level.
017     *
018     * @param context ExceptionDebugLogging the exception intercepting context.
019     * @param error Throwable the intercepted error.
020     * @param logger Logger the logger to use
021     */
022    default void debugException(final ExceptionDebugLogging context, final Throwable error, final Logger logger) {
023        /*
024         * Because the majority case is not debug logging, trade one additional
025         * accessor call in a guard clause for multiple in message construction
026         * and internal log level checks
027         */
028        if (!logger.isDebugEnabled()) {
029            return;
030        }
031        logger.debug("{} intercepted exception:{} \n", context.getClass()
032                .getSimpleName(), error);
033        logger.trace(error.getMessage(), error);
034    }
035}