protected static List < StackTraceElement > filterStackTrace ( StackTraceElement [ ] stack ) { List < StackTraceElement > filteredStack = new ArrayList < StackTraceElement > ( ) ; 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 ) { filteredStack . add ( stack [ i ] ) ; } i += 1 ; } // if we didn't find anything, keep the full stack if ( filteredStack . size ( ) == 0 ) { return Arrays . asList ( stack ) ; } return filteredStack ; }
Removes logging classes from a stack trace .