001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache license, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the license for the specific language governing permissions and
015 * limitations under the license.
016 */
017package org.apache.logging.log4j.core.appender;
018
019import org.apache.logging.log4j.LoggingException;
020
021/**
022 * Thrown from an appender when a log event could not be written. Appenders should not thrown an exception if an error
023 * occurs that does <em>not</em> stop the event from being successfully written. Those types of errors should be logged
024 * using the {@link org.apache.logging.log4j.status.StatusLogger}. Appenders should only throw exceptions when an error
025 * prevents an event from being written. Appenders <em>must</em> throw an exception in this case so that error-handling
026 * features like the {@link FailoverAppender} work properly.
027 * <p>
028 * Also note that appenders <em>must</em> provide a way to suppress exceptions when the user desires and abide by
029 * that instruction. See {@link org.apache.logging.log4j.core.Appender#ignoreExceptions()}, which is the standard
030 * way to do this.
031 * </p>
032 */
033public class AppenderLoggingException extends LoggingException {
034
035    private static final long serialVersionUID = 6545990597472958303L;
036
037    /**
038     * Constructs an exception with a message.
039     *
040     * @param message The reason for the exception
041     */
042    public AppenderLoggingException(final String message) {
043        super(message);
044    }
045
046    /**
047     * Constructs an exception with a message.
048     *
049     * @param format The reason format for the exception, see {@link String#format(String, Object...)}.
050     * @param args The reason arguments for the exception, see {@link String#format(String, Object...)}.
051     * @since 2.12.1
052     */
053    public AppenderLoggingException(final String format, Object... args) {
054        super(String.format(format, args));
055    }
056
057    /**
058     * Constructs an exception with a message and underlying cause.
059     *
060     * @param message The reason for the exception
061     * @param cause The underlying cause of the exception
062     */
063    public AppenderLoggingException(final String message, final Throwable cause) {
064        super(message, cause);
065    }
066
067    /**
068     * Constructs an exception with an underlying cause.
069     *
070     * @param cause The underlying cause of the exception
071     */
072    public AppenderLoggingException(final Throwable cause) {
073        super(cause);
074    }
075
076    /**
077     * Constructs an exception with a message.
078     *
079     * @param cause The underlying cause of the exception
080     * @param format The reason format for the exception, see {@link String#format(String, Object...)}.
081     * @param args The reason arguments for the exception, see {@link String#format(String, Object...)}.
082     * @since 2.12.1
083     */
084    public AppenderLoggingException(final Throwable cause, final String format, Object... args) {
085        super(String.format(format, args), cause);
086    }
087}