1 55 56 package org.apache.avalon.framework.logger; 57 58 import org.apache.log.Hierarchy; 59 import org.apache.log.LogEvent; 60 import org.apache.log.LogTarget; 61 import org.apache.log.Priority; 62 63 71 public final class LogKit2AvalonLoggerAdapter 72 implements LogTarget 73 { 74 77 private final Logger m_logger; 78 79 86 public static org.apache.log.Logger createLogger( final Logger logger ) 87 { 88 final Hierarchy hierarchy = new Hierarchy(); 89 final org.apache.log.Logger logKitLogger = hierarchy.getLoggerFor( "" ); 90 final LogKit2AvalonLoggerAdapter target = 91 new LogKit2AvalonLoggerAdapter( logger ); 92 logKitLogger.setLogTargets( new LogTarget[ ] { target } ); 93 return logKitLogger; 94 } 95 96 102 public LogKit2AvalonLoggerAdapter( final Logger logger ) 103 { 104 if( null == logger ) 105 { 106 throw new NullPointerException ( "logger" ); 107 } 108 m_logger = logger; 109 } 110 111 116 public void processEvent( LogEvent event ) 117 { 118 final String message = event.getMessage(); 119 final Throwable throwable = event.getThrowable(); 120 final Priority priority = event.getPriority(); 121 if( Priority.DEBUG == priority ) 122 { 123 m_logger.debug( message, throwable ); 124 } 125 else if( Priority.INFO == priority ) 126 { 127 m_logger.info( message, throwable ); 128 } 129 else if( Priority.WARN == priority ) 130 { 131 m_logger.warn( message, throwable ); 132 } 133 else if( Priority.ERROR == priority ) 134 { 135 m_logger.error( message, throwable ); 136 } 137 else 138 { 139 m_logger.fatalError( message, throwable ); 140 } 141 } 142 } 143 | Popular Tags |