1 19 package org.apache.avalon.excalibur.logger.logkit; 20 21 import org.apache.avalon.framework.logger.Logger; 22 import org.apache.log.ErrorHandler; 23 import org.apache.log.Priority; 24 import org.apache.log.LogEvent; 25 26 34 35 public class ErrorHandlerAdapter implements ErrorHandler 36 { 37 private final Logger m_reliableLogger; 38 39 public ErrorHandlerAdapter( final Logger reliableLogger ) 40 { 41 if ( reliableLogger == null ) 42 { 43 throw new NullPointerException ( "reliableLogger" ); 44 } 45 m_reliableLogger = reliableLogger; 46 } 47 48 public void error( final String message, final Throwable throwable, final LogEvent event ) 49 { 50 m_reliableLogger.fatalError( message, throwable ); 52 53 final Priority p = event.getPriority(); 55 final String nestedMessage = "nested log event: " + event.getMessage(); 56 57 if ( p == Priority.DEBUG ) 58 { 59 m_reliableLogger.debug( nestedMessage, event.getThrowable() ); 60 } 61 else if ( p == Priority.INFO ) 62 { 63 m_reliableLogger.info( nestedMessage, event.getThrowable() ); 64 } 65 else if ( p == Priority.WARN ) 66 { 67 m_reliableLogger.warn( nestedMessage, event.getThrowable() ); 68 } 69 else if ( p == Priority.ERROR ) 70 { 71 m_reliableLogger.error( nestedMessage, event.getThrowable() ); 72 } 73 else if ( p == Priority.FATAL_ERROR) 74 { 75 m_reliableLogger.fatalError( nestedMessage, event.getThrowable() ); 76 } 77 else 78 { 79 80 m_reliableLogger.error( "unrecognized priority " + nestedMessage, 81 event.getThrowable() ); 82 } 83 } 84 } 85 | Popular Tags |