1 22 23 package org.jboss.logging.util; 24 25 import java.io.PrintStream ; 26 27 import org.apache.log4j.spi.ErrorHandler; 28 import org.apache.log4j.spi.LoggingEvent; 29 import org.apache.log4j.Logger; 30 import org.apache.log4j.Appender; 31 32 46 public class OnlyOnceErrorHandler implements ErrorHandler { 47 48 49 final String WARN_PREFIX = "log4j warning: "; 50 final String ERROR_PREFIX = "log4j error: "; 51 52 boolean firstTime = true; 53 54 static PrintStream output = System.err; 55 56 public static void setOutput(PrintStream out) 57 { 58 output = out; 59 } 60 61 64 public 65 void setLogger(Logger logger) { 66 } 67 68 69 72 public 73 void activateOptions() { 74 } 75 76 77 80 public 81 void error(String message, Exception e, int errorCode) { 82 error(message, e, errorCode, null); 83 } 84 85 89 public 90 void error(String message, Exception e, int errorCode, LoggingEvent event) { 91 if(firstTime) { 92 output.println(ERROR_PREFIX + message); 93 e.printStackTrace(output); 94 firstTime = false; 95 } 96 } 97 98 99 103 public 104 void error(String message) { 105 if(firstTime) { 106 output.println(ERROR_PREFIX + message); 107 firstTime = false; 108 } 109 } 110 111 114 public 115 void setAppender(Appender appender) { 116 } 117 118 121 public 122 void setBackupAppender(Appender appender) { 123 } 124 } 125 | Popular Tags |