1 23 24 package com.sun.jdo.spi.persistence.utility.logging; 25 26 import java.util.logging.Level ; 27 import java.util.logging.LogManager ; 28 29 import java.lang.StringBuffer ; 30 31 39 public class LoggerJDK14 extends java.util.logging.Logger implements Logger { 40 41 42 protected String sourceClassName; 43 44 45 protected String sourceMethodName; 46 47 52 public LoggerJDK14(String loggerName, String bundleName) { 53 super (loggerName, bundleName); 54 } 55 56 64 public boolean isLoggable() { 65 return isLoggable(Level.FINE); 66 } 67 68 78 public void fine(String msg, Object [] o) { 79 if (isLoggable(Level.FINE)) { 80 inferCaller(); 81 logp(Level.FINE, sourceClassName, sourceMethodName, msg, o); 82 } 83 } 84 85 95 public void fine(String msg, Object o1) { 96 if (isLoggable(Level.FINE)) { 97 inferCaller(); 98 logp(Level.FINE, sourceClassName, sourceMethodName, msg, o1); 99 } 100 } 101 102 103 114 public void fine(String msg, Object o1, Object o2) { 115 if (isLoggable(Level.FINE)) { 116 inferCaller(); 117 logp(Level.FINE, sourceClassName, sourceMethodName, msg, new Object []{o1, o2}); 118 } 119 } 120 121 133 public void fine(String msg, Object o1, Object o2, Object o3) { 134 if (isLoggable(Level.FINE)) { 135 inferCaller(); 136 logp(Level.FINE, sourceClassName, sourceMethodName, msg, new Object []{o1, o2, o3}); 137 } 138 } 139 140 150 public void finer(String msg, Object [] o) { 151 if (isLoggable(Level.FINER)) { 152 inferCaller(); 153 logp(Level.FINER, sourceClassName, sourceMethodName, msg, o); 154 } 155 } 156 157 167 public void finer(String msg, Object o1) { 168 if (isLoggable(Level.FINER)) { 169 inferCaller(); 170 logp(Level.FINER, sourceClassName, sourceMethodName, msg, o1); 171 } 172 } 173 174 175 186 public void finer(String msg, Object o1, Object o2) { 187 if (isLoggable(Level.FINER)) { 188 inferCaller(); 189 logp(Level.FINER, sourceClassName, sourceMethodName, msg, 190 new Object []{o1, o2}); 191 } 192 } 193 194 206 public void finer(String msg, Object o1, Object o2, Object o3) { 207 if (isLoggable(Level.FINER)) { 208 inferCaller(); 209 logp(Level.FINER, sourceClassName, sourceMethodName, msg, 210 new Object []{o1, o2, o3}); 211 } 212 } 213 214 215 225 public void finest(String msg, Object [] o) { 226 if (isLoggable(Level.FINEST)) { 227 inferCaller(); 228 logp(Level.FINEST, sourceClassName, sourceMethodName, msg, o); 229 } 230 } 231 232 242 public void finest(String msg, Object o1) { 243 if (isLoggable(Level.FINEST)) { 244 inferCaller(); 245 logp(Level.FINEST, sourceClassName, sourceMethodName, msg, o1); 246 } 247 } 248 249 260 public void finest(String msg, Object o1, Object o2) { 261 if (isLoggable(Level.FINEST)) { 262 inferCaller(); 263 logp(Level.FINEST, sourceClassName, sourceMethodName, msg, 264 new Object []{o1, o2}); 265 } 266 } 267 268 280 public void finest(String msg, Object o1, Object o2, Object o3) { 281 if (isLoggable(Level.FINEST)) { 282 inferCaller(); 283 logp(Level.FINEST, sourceClassName, sourceMethodName, msg, 284 new Object []{o1, o2, o3}); 285 } 286 } 287 288 291 public String toString() { 292 StringBuffer buf = new StringBuffer ("LoggerJDK14: "); buf.append (" name: "); buf.append (getName()); buf.append (", super: "); buf.append (super.toString()); buf.append (", logging level: "); buf.append (getLevel()); return buf.toString(); 297 } 298 299 310 public void log(int level, String msg, Object o1) { 311 Level lvl = convertLevel(level); 312 if (isLoggable(lvl)) { 313 inferCaller(); 314 logp(lvl, sourceClassName, sourceMethodName, msg, o1); 315 } 316 } 317 318 330 public void log(int level, String msg, Object o1, Object o2) { 331 Level lvl = convertLevel(level); 332 if (isLoggable(lvl)) { 333 inferCaller(); 334 logp(lvl, sourceClassName, sourceMethodName, msg, new Object []{o1, o2}); 335 } 336 } 337 338 351 public void log(int level, String msg, Object o1, Object o2, Object o3) { 352 Level lvl = convertLevel(level); 353 if (isLoggable(lvl)) { 354 inferCaller(); 355 logp(lvl, sourceClassName, sourceMethodName, msg, 356 new Object [] {o1, o2, o3}); 357 } 358 } 359 360 371 public void log(int level, String msg, Object [] o) { 372 Level lvl = convertLevel(level); 373 if (isLoggable(lvl)) { 374 inferCaller(); 375 logp(lvl, sourceClassName, sourceMethodName, msg, o); 376 } 377 } 378 379 389 public void log(int level, String msg) { 390 Level lvl = convertLevel(level); 391 if (isLoggable(lvl)) { 392 inferCaller(); 393 logp(lvl, sourceClassName, sourceMethodName, msg); 394 } 395 } 396 397 398 410 public void log(int level, String msg, Throwable thrown ){ 411 Level lvl = convertLevel(level); 412 if (isLoggable(lvl)) { 413 inferCaller(); 414 logp(lvl, sourceClassName, sourceMethodName, msg, thrown); 415 } 416 } 417 418 426 public boolean isLoggable(int levelValue) { 427 return isLoggable(convertLevel(levelValue)); 428 } 429 430 437 protected Level convertLevel(int level) { 438 int index = level/100; 439 switch (index) { 440 case 3: return Level.FINEST; 441 case 4: return Level.FINER; 442 case 5: return Level.FINE; 443 case 7: return Level.CONFIG; 444 case 8: return Level.INFO; 445 case 9: return Level.WARNING; 446 case 10: return Level.SEVERE; 447 default: return Level.CONFIG; 448 } 449 } 450 451 457 protected void inferCaller() { 458 StackTraceElement [] stack = (new Throwable ()).getStackTrace(); 460 for(int ix = 0; ix < stack.length; ix++) { 462 StackTraceElement frame = stack[ix]; 463 String cname = frame.getClassName(); 464 if (!isLoggerClass(cname)) { 465 sourceClassName = cname; 467 sourceMethodName = frame.getMethodName(); 468 return; 469 } 470 } 471 } 472 473 482 protected boolean isLoggerClass(String className) 483 { 484 return "com.sun.jdo.spi.persistence.utility.logging.LoggerJDK14". equals(className); 486 } 487 } 488 | Popular Tags |