private static StackTraceElement getStackTrace ( ) { StackTraceElement [ ] stack = Thread . currentThread ( ) . getStackTrace ( ) ; int i = 2 ; // we can skip the first two (first is getStackTrace(), second is this method) while ( i < stack . length ) { boolean isLoggingClass = false ; for ( String loggingClass : loggingClasses ) { String className = stack [ i ] . getClassName ( ) ; if ( className . startsWith ( loggingClass ) ) { isLoggingClass = true ; break ; } } if ( ! isLoggingClass ) { break ; } i += 1 ; } // if we didn't find anything, keep last element (probably shouldn't happen, but could if people add too many logging classes) if ( i >= stack . length ) { i = stack . length - 1 ; } return stack [ i ] ; }
Get the current stack trace element skipping anything from known logging classes .