1 19 package org.apache.avalon.excalibur.logger; 20 21 import org.apache.avalon.framework.logger.Logger; 22 import org.apache.log4j.Level; 23 24 32 public class Log4JLogger 33 implements Logger 34 { 35 36 40 private static final String FQCN = Log4JLogger.class.getName(); 41 42 43 private final org.apache.log4j.Logger m_logger; 44 45 private final boolean m_isDebugEnabled; 46 private final boolean m_isInfoEnabled; 47 private final boolean m_isWarnEnabled; 48 private final boolean m_isErrorEnabled; 49 private final boolean m_isFatalErrorEnabled; 50 51 56 public Log4JLogger( final org.apache.log4j.Logger logImpl ) 57 { 58 m_logger = logImpl; 59 m_isDebugEnabled = logImpl.isDebugEnabled(); 60 m_isInfoEnabled = logImpl.isInfoEnabled(); 61 m_isWarnEnabled = logImpl.isEnabledFor( Level.WARN ); 62 m_isErrorEnabled = logImpl.isEnabledFor( Level.ERROR ); 63 m_isFatalErrorEnabled = logImpl.isEnabledFor( Level.FATAL ); 64 } 65 66 71 public final void debug( final String message ) 72 { 73 if ( m_isDebugEnabled ) 74 m_logger.log( FQCN, Level.DEBUG, message, null ); 75 } 76 77 83 public final void debug( final String message, final Throwable throwable ) 84 { 85 if ( m_isDebugEnabled ) 86 m_logger.log( FQCN, Level.DEBUG, message, throwable ); 87 } 88 89 94 public final boolean isDebugEnabled() 95 { 96 return m_isDebugEnabled; 97 } 98 99 104 public final void info( final String message ) 105 { 106 if ( m_isInfoEnabled ) 107 m_logger.log( FQCN, Level.INFO, message, null ); 108 } 109 110 116 public final void info( final String message, final Throwable throwable ) 117 { 118 if ( m_isInfoEnabled ) 119 m_logger.log( FQCN, Level.INFO, message, throwable ); 120 } 121 122 127 public final boolean isInfoEnabled() 128 { 129 return m_isInfoEnabled; 130 } 131 132 137 public final void warn( final String message ) 138 { 139 if ( m_isWarnEnabled ) 140 m_logger.log( FQCN, Level.WARN, message, null ); 141 } 142 143 149 public final void warn( final String message, final Throwable throwable ) 150 { 151 if ( m_isWarnEnabled ) 152 m_logger.log( FQCN, Level.WARN, message, throwable ); 153 } 154 155 160 public final boolean isWarnEnabled() 161 { 162 return m_isWarnEnabled; 163 } 164 165 170 public final void error( final String message ) 171 { 172 if ( m_isErrorEnabled ) 173 m_logger.log( FQCN, Level.ERROR, message, null ); 174 } 175 176 182 public final void error( final String message, final Throwable throwable ) 183 { 184 if ( m_isErrorEnabled ) 185 m_logger.log( FQCN, Level.ERROR, message, throwable ); 186 } 187 188 193 public final boolean isErrorEnabled() 194 { 195 return m_isErrorEnabled; 196 } 197 198 203 public final void fatalError( final String message ) 204 { 205 if ( m_isFatalErrorEnabled ) 206 m_logger.log( FQCN, Level.FATAL, message, null ); 207 } 208 209 215 public final void fatalError( final String message, final Throwable throwable ) 216 { 217 if ( m_isFatalErrorEnabled ) 218 m_logger.log( FQCN, Level.ERROR, message, throwable ); 219 } 220 221 226 public final boolean isFatalErrorEnabled() 227 { 228 return m_isFatalErrorEnabled; 229 } 230 231 239 public final Logger getChildLogger( final String name ) 240 { 241 return new Log4JLogger( org.apache.log4j.Logger.getLogger( m_logger.getName() + "." + name ) ); 242 } 243 244 } 245 | Popular Tags |