1 17 18 package org.apache.geronimo.system.logging.log4j; 19 20 import org.apache.commons.logging.Log; 21 import org.apache.log4j.Level; 22 import org.apache.log4j.Logger; 23 24 30 public final class CachingLog4jLog implements Log { 31 private final String FQCN = getClass().getName(); 32 private Logger logger; 33 private boolean traceEnabled; 34 private boolean debugEnabled; 35 private boolean infoEnabled; 36 37 public CachingLog4jLog(String name) { 38 logger = Logger.getLogger(name); 39 updateLevelInfo(); 40 } 41 42 public CachingLog4jLog(Logger logger) { 43 this.logger = logger; 44 updateLevelInfo(); 45 } 46 47 public boolean isTraceEnabled() { 48 return traceEnabled; 49 } 50 51 public void trace(Object message) { 52 if (traceEnabled) { 53 logger.log(FQCN, XLevel.TRACE, message, null); 54 } 55 } 56 57 public void trace(Object message, Throwable throwable) { 58 if (traceEnabled) { 59 logger.log(FQCN, XLevel.TRACE, message, throwable); 60 } 61 } 62 63 public boolean isDebugEnabled() { 64 return debugEnabled; 65 } 66 67 public void debug(Object message) { 68 if (debugEnabled) { 69 logger.log(FQCN, Level.DEBUG, message, null); 70 } 71 } 72 73 public void debug(Object message, Throwable throwable) { 74 if (debugEnabled) { 75 logger.log(FQCN, Level.DEBUG, message, throwable); 76 } 77 } 78 79 public boolean isInfoEnabled() { 80 return infoEnabled; 81 } 82 83 public void info(Object message) { 84 if (infoEnabled) { 85 logger.log(FQCN, Level.INFO, message, null); 86 } 87 } 88 89 public void info(Object message, Throwable throwable) { 90 if (infoEnabled) { 91 logger.log(FQCN, Level.INFO, message, throwable); 92 } 93 } 94 95 public boolean isWarnEnabled() { 96 return logger.isEnabledFor(Level.WARN); 97 } 98 99 public void warn(Object message) { 100 logger.log(FQCN, Level.WARN, message, null); 101 } 102 103 public void warn(Object message, Throwable throwable) { 104 logger.log(FQCN, Level.WARN, message, throwable); 105 } 106 107 public boolean isErrorEnabled() { 108 return logger.isEnabledFor(Level.ERROR); 109 } 110 111 public void error(Object message) { 112 logger.log(FQCN, Level.ERROR, message, null); 113 } 114 115 public void error(Object message, Throwable throwable) { 116 logger.log(FQCN, Level.ERROR, message, throwable); 117 } 118 119 public boolean isFatalEnabled() { 120 return logger.isEnabledFor(Level.FATAL); 121 } 122 123 public void fatal(Object message) { 124 logger.log(FQCN, Level.FATAL, message, null); 125 } 126 127 public void fatal(Object message, Throwable throwable) { 128 logger.log(FQCN, Level.FATAL, message, throwable); 129 } 130 131 public void updateLevelInfo() { 132 traceEnabled = logger.isEnabledFor(XLevel.TRACE); 137 debugEnabled = logger.isDebugEnabled(); 138 infoEnabled = logger.isInfoEnabled(); 139 } 140 } 141 | Popular Tags |