1 16 17 18 package org.apache.commons.logging.impl; 19 20 21 import java.io.Serializable ; 22 import java.util.logging.Level ; 23 import java.util.logging.Logger ; 24 25 import org.apache.commons.logging.Log; 26 27 28 38 39 public class Jdk14Logger implements Log, Serializable { 40 41 47 protected static final Level dummyLevel = Level.FINE; 48 49 51 52 57 public Jdk14Logger(String name) { 58 59 this.name = name; 60 logger = getLogger(); 61 62 } 63 64 65 67 68 71 protected transient Logger logger = null; 72 73 74 77 protected String name = null; 78 79 80 82 private void log( Level level, String msg, Throwable ex ) { 83 84 Logger logger = getLogger(); 85 if (logger.isLoggable(level)) { 86 Throwable dummyException=new Throwable (); 88 StackTraceElement locations[]=dummyException.getStackTrace(); 89 String cname="unknown"; 91 String method="unknown"; 92 if( locations!=null && locations.length >2 ) { 93 StackTraceElement caller=locations[2]; 94 cname=caller.getClassName(); 95 method=caller.getMethodName(); 96 } 97 if( ex==null ) { 98 logger.logp( level, cname, method, msg ); 99 } else { 100 logger.logp( level, cname, method, msg, ex ); 101 } 102 } 103 104 } 105 106 112 public void debug(Object message) { 113 log(Level.FINE, String.valueOf(message), null); 114 } 115 116 117 124 public void debug(Object message, Throwable exception) { 125 log(Level.FINE, String.valueOf(message), exception); 126 } 127 128 129 135 public void error(Object message) { 136 log(Level.SEVERE, String.valueOf(message), null); 137 } 138 139 140 147 public void error(Object message, Throwable exception) { 148 log(Level.SEVERE, String.valueOf(message), exception); 149 } 150 151 152 158 public void fatal(Object message) { 159 log(Level.SEVERE, String.valueOf(message), null); 160 } 161 162 163 170 public void fatal(Object message, Throwable exception) { 171 log(Level.SEVERE, String.valueOf(message), exception); 172 } 173 174 175 178 public Logger getLogger() { 179 if (logger == null) { 180 logger = Logger.getLogger(name); 181 } 182 return (logger); 183 } 184 185 186 192 public void info(Object message) { 193 log(Level.INFO, String.valueOf(message), null); 194 } 195 196 197 204 public void info(Object message, Throwable exception) { 205 log(Level.INFO, String.valueOf(message), exception); 206 } 207 208 209 212 public boolean isDebugEnabled() { 213 return (getLogger().isLoggable(Level.FINE)); 214 } 215 216 217 220 public boolean isErrorEnabled() { 221 return (getLogger().isLoggable(Level.SEVERE)); 222 } 223 224 225 228 public boolean isFatalEnabled() { 229 return (getLogger().isLoggable(Level.SEVERE)); 230 } 231 232 233 236 public boolean isInfoEnabled() { 237 return (getLogger().isLoggable(Level.INFO)); 238 } 239 240 241 244 public boolean isTraceEnabled() { 245 return (getLogger().isLoggable(Level.FINEST)); 246 } 247 248 249 252 public boolean isWarnEnabled() { 253 return (getLogger().isLoggable(Level.WARNING)); 254 } 255 256 257 263 public void trace(Object message) { 264 log(Level.FINEST, String.valueOf(message), null); 265 } 266 267 268 275 public void trace(Object message, Throwable exception) { 276 log(Level.FINEST, String.valueOf(message), exception); 277 } 278 279 280 286 public void warn(Object message) { 287 log(Level.WARNING, String.valueOf(message), null); 288 } 289 290 291 298 public void warn(Object message, Throwable exception) { 299 log(Level.WARNING, String.valueOf(message), exception); 300 } 301 302 303 } 304 | Popular Tags |