2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.apache.log4j.helpers;
20 import org.apache.log4j.spi.ErrorHandler;
21 import org.apache.log4j.spi.LoggingEvent;
22 import org.apache.log4j.Logger;
23 import org.apache.log4j.Appender;
25 import java.io.InterruptedIOException;
29 The <code>OnlyOnceErrorHandler</code> implements log4j's default
30 error handling policy which consists of emitting a message for the
31 first error in an appender and ignoring all following errors.
33 <p>The error message is printed on <code>System.err</code>.
35 <p>This policy aims at protecting an otherwise working application
36 from being flooded with error messages when logging fails.
38 @author Ceki Gülcü
40 public class OnlyOnceErrorHandler implements ErrorHandler {
43 final String WARN_PREFIX = "log4j warning: ";
44 final String ERROR_PREFIX = "log4j error: ";
46 boolean firstTime = true;
53 void setLogger(Logger logger) {
58 No options to activate.
61 void activateOptions() {
66 Prints the message and the stack trace of the exception on
67 <code>System.err</code>. */
69 void error(String message, Exception e, int errorCode) {
70 error(message, e, errorCode, null);
74 Prints the message and the stack trace of the exception on
75 <code>System.err</code>.
78 void error(String message, Exception e, int errorCode, LoggingEvent event) {
79 if (e instanceof InterruptedIOException || e instanceof InterruptedException) {
80 Thread.currentThread().interrupt();
83 LogLog.error(message, e);
90 Print a the error message passed as parameter on
91 <code>System.err</code>.
94 void error(String message) {
96 LogLog.error(message);
102 Does not do anything.
105 void setAppender(Appender appender) {
109 Does not do anything.
112 void setBackupAppender(Appender appender) {