1 7 8 package com.sun.corba.se.spi.logging ; 9 10 import java.util.logging.Level ; 11 import java.util.logging.Logger ; 12 import java.util.logging.LogRecord ; 13 14 public abstract class LogWrapperBase { 15 protected Logger logger ; 16 17 protected String loggerName ; 18 19 protected LogWrapperBase( Logger logger ) 20 { 21 this.logger = logger ; 22 this.loggerName = logger.getName( ); 23 } 24 25 protected void doLog( Level level, String key, Object [] params, Class wrapperClass, 26 Throwable thr ) 27 { 28 LogRecord lrec = new LogRecord ( level, key ) ; 29 if (params != null) 30 lrec.setParameters( params ) ; 31 inferCaller( wrapperClass, lrec ) ; 32 lrec.setThrown( thr ) ; 33 lrec.setLoggerName( loggerName ); 34 lrec.setResourceBundle( logger.getResourceBundle() ) ; 35 logger.log( lrec ) ; 36 } 37 38 private void inferCaller( Class wrapperClass, LogRecord lrec ) 39 { 40 42 StackTraceElement stack[] = (new Throwable ()).getStackTrace(); 44 StackTraceElement frame = null ; 45 String wcname = wrapperClass.getName() ; 46 String baseName = LogWrapperBase.class.getName() ; 47 48 int ix = 0; 52 while (ix < stack.length) { 53 frame = stack[ix]; 54 String cname = frame.getClassName(); 55 if (!cname.equals(wcname) && !cname.equals(baseName)) { 56 break; 57 } 58 59 ix++; 60 } 61 62 if (ix < stack.length) { 65 lrec.setSourceClassName(frame.getClassName()); 66 lrec.setSourceMethodName(frame.getMethodName()); 67 } 68 } 69 70 protected void doLog( Level level, String key, Class wrapperClass, Throwable thr ) 71 { 72 doLog( level, key, null, wrapperClass, thr ) ; 73 } 74 } 75 | Popular Tags |