1 22 package org.jboss.logging.log4j; 23 24 import org.apache.log4j.LogManager; 25 import org.apache.log4j.Level; 26 import org.apache.log4j.Category; 27 import org.apache.log4j.Priority; 28 import org.jboss.logging.Logger; 29 import org.jboss.logging.LoggerPlugin; 30 import org.jboss.logging.XLevel; 31 32 55 56 public class Log4jLoggerPlugin implements LoggerPlugin 57 { 58 59 61 65 private static final String FQCN = Logger.class.getName(); 66 67 69 70 private transient org.apache.log4j.Logger log; 71 72 74 76 public Log4jLoggerPlugin () { } 77 78 public void init (String name) 79 { 80 log = LogManager.getLogger(name); 81 } 82 83 85 public Category getCategory() 86 { 87 return log; 88 } 89 90 93 public org.apache.log4j.Logger getLogger() 94 { 95 return log; 96 } 97 98 100 public boolean isTraceEnabled() 101 { 102 if (log.isEnabledFor(XLevel.TRACE) == false) 103 return false; 104 return XLevel.TRACE.isGreaterOrEqual(log.getEffectiveLevel()); 105 } 106 107 111 public void trace(Object message) 112 { 113 log.log(FQCN, XLevel.TRACE, message, null); 114 } 115 116 120 public void trace(Object message, Throwable t) 121 { 122 log.log(FQCN, XLevel.TRACE, message, t); 123 } 124 125 131 public boolean isDebugEnabled() 132 { 133 Level l = Level.DEBUG; 134 if (log.isEnabledFor(l) == false) 135 return false; 136 return l.isGreaterOrEqual(log.getEffectiveLevel()); 137 } 138 139 143 public void debug(Object message) 144 { 145 log.log(FQCN, Level.DEBUG, message, null); 146 } 147 148 152 public void debug(Object message, Throwable t) 153 { 154 log.log(FQCN, Level.DEBUG, message, t); 155 } 156 157 163 public boolean isInfoEnabled() 164 { 165 Level l = Level.INFO; 166 if (log.isEnabledFor(l) == false) 167 return false; 168 return l.isGreaterOrEqual(log.getEffectiveLevel()); 169 } 170 171 175 public void info(Object message) 176 { 177 log.log(FQCN, Level.INFO, message, null); 178 } 179 180 184 public void info(Object message, Throwable t) 185 { 186 log.log(FQCN, Level.INFO, message, t); 187 } 188 189 193 public void warn(Object message) 194 { 195 log.log(FQCN, Level.WARN, message, null); 196 } 197 198 202 public void warn(Object message, Throwable t) 203 { 204 log.log(FQCN, Level.WARN, message, t); 205 } 206 207 211 public void error(Object message) 212 { 213 log.log(FQCN, Level.ERROR, message, null); 214 } 215 216 220 public void error(Object message, Throwable t) 221 { 222 log.log(FQCN, Level.ERROR, message, t); 223 } 224 225 229 public void fatal(Object message) 230 { 231 log.log(FQCN, Level.FATAL, message, null); 232 } 233 234 238 public void fatal(Object message, Throwable t) 239 { 240 log.log(FQCN, Level.FATAL, message, t); 241 } 242 243 249 public void log(Priority p, Object message) 250 { 251 log.log(FQCN, p, message, null); 252 } 253 254 260 public void log(Priority p, Object message, Throwable t) 261 { 262 log.log(FQCN, p, message, t); 263 } 264 265 269 public void log(Level l, Object message) 270 { 271 log.log(FQCN, l, message, null); 272 } 273 274 278 public void log(Level l, Object message, Throwable t) 279 { 280 log.log(FQCN, l, message, t); 281 } 282 283 285 287 289 291 293 } 294 | Popular Tags |