protected String [ ] inferCaller ( ) { String self = getClass ( ) . getName ( ) ; // locate ourselves in the call stack StackTraceElement [ ] stack = ( new Throwable ( ) ) . getStackTrace ( ) ; int ii = 0 ; for ( ; ii < stack . length ; ii ++ ) { if ( self . equals ( stack [ ii ] . getClassName ( ) ) ) { break ; } } System . err . println ( "Found self at " + ii ) ; // now locate the first thing that's not us, that's the caller for ( ; ii < stack . length ; ii ++ ) { String cname = stack [ ii ] . getClassName ( ) ; if ( ! cname . equals ( self ) ) { System . err . println ( "Found non-self at " + ii + " " + cname ) ; return new String [ ] { cname , stack [ ii ] . getMethodName ( ) } ; } } System . err . println ( "Failed to find non-self." ) ; return new String [ ] { null , null } ; }
Infers the caller of a Logger method from the current stack trace . This can be used by wrappers to provide the correct calling class and method information to their underlying log implementation .