1 16 17 18 package org.apache.commons.logging.impl; 19 20 import java.io.Serializable ; 21 import org.apache.commons.logging.Log; 22 import org.apache.log4j.Logger; 23 import org.apache.log4j.Priority; 24 import org.apache.log4j.Level; 25 26 48 49 public class Log4JLogger implements Log, Serializable { 50 51 53 54 private static final String FQCN = Log4JLogger.class.getName(); 55 56 57 private transient Logger logger = null; 58 59 60 private String name = null; 61 62 private static Priority traceLevel; 63 64 78 static { 79 if (!Priority.class.isAssignableFrom(Level.class)) { 80 throw new InstantiationError ("Log4J 1.2 not available"); 82 } 83 84 88 try { 89 traceLevel = (Priority) Level.class.getDeclaredField("TRACE").get(null); 90 } catch(Exception ex) { 91 traceLevel = Priority.DEBUG; 93 } 94 } 95 96 97 99 public Log4JLogger() { 100 } 101 102 103 106 public Log4JLogger(String name) { 107 this.name = name; 108 this.logger = getLogger(); 109 } 110 111 113 public Log4JLogger(Logger logger ) { 114 this.name = logger.getName(); 115 this.logger=logger; 116 } 117 118 119 136 137 145 public void trace(Object message) { 146 getLogger().log(FQCN, traceLevel, message, null ); 147 } 148 149 150 159 public void trace(Object message, Throwable t) { 160 getLogger().log(FQCN, traceLevel, message, t ); 161 } 162 163 164 170 public void debug(Object message) { 171 getLogger().log(FQCN, Priority.DEBUG, message, null ); 172 } 173 174 181 public void debug(Object message, Throwable t) { 182 getLogger().log(FQCN, Priority.DEBUG, message, t ); 183 } 184 185 186 192 public void info(Object message) { 193 getLogger().log(FQCN, Priority.INFO, message, null ); 194 } 195 196 197 204 public void info(Object message, Throwable t) { 205 getLogger().log(FQCN, Priority.INFO, message, t ); 206 } 207 208 209 215 public void warn(Object message) { 216 getLogger().log(FQCN, Priority.WARN, message, null ); 217 } 218 219 220 227 public void warn(Object message, Throwable t) { 228 getLogger().log(FQCN, Priority.WARN, message, t ); 229 } 230 231 232 238 public void error(Object message) { 239 getLogger().log(FQCN, Priority.ERROR, message, null ); 240 } 241 242 243 250 public void error(Object message, Throwable t) { 251 getLogger().log(FQCN, Priority.ERROR, message, t ); 252 } 253 254 255 261 public void fatal(Object message) { 262 getLogger().log(FQCN, Priority.FATAL, message, null ); 263 } 264 265 266 273 public void fatal(Object message, Throwable t) { 274 getLogger().log(FQCN, Priority.FATAL, message, t ); 275 } 276 277 278 281 public Logger getLogger() { 282 if (logger == null) { 283 logger = Logger.getLogger(name); 284 } 285 return (this.logger); 286 } 287 288 289 292 public boolean isDebugEnabled() { 293 return getLogger().isDebugEnabled(); 294 } 295 296 297 300 public boolean isErrorEnabled() { 301 return getLogger().isEnabledFor(Priority.ERROR); 302 } 303 304 305 308 public boolean isFatalEnabled() { 309 return getLogger().isEnabledFor(Priority.FATAL); 310 } 311 312 313 316 public boolean isInfoEnabled() { 317 return getLogger().isInfoEnabled(); 318 } 319 320 321 326 public boolean isTraceEnabled() { 327 return getLogger().isEnabledFor(traceLevel); 328 } 329 330 333 public boolean isWarnEnabled() { 334 return getLogger().isEnabledFor(Priority.WARN); 335 } 336 } 337 | Popular Tags |