public static void printCallstack ( final Level logLevel , final String [ ] carePackages , final String [ ] exceptablePackages ) { if ( null == logLevel ) { LOGGER . log ( Level . WARN , "Requires parameter [logLevel]" ) ; return ; } final Throwable throwable = new Throwable ( ) ; final StackTraceElement [ ] stackElements = throwable . getStackTrace ( ) ; if ( null == stackElements ) { LOGGER . log ( Level . WARN , "Empty call stack" ) ; return ; } final long tId = Thread . currentThread ( ) . getId ( ) ; final StringBuilder stackBuilder = new StringBuilder ( "CallStack [tId=" ) . append ( tId ) . append ( Strings . LINE_SEPARATOR ) ; for ( int i = 1 ; i < stackElements . length ; i ++ ) { final String stackElemClassName = stackElements [ i ] . getClassName ( ) ; if ( ! StringUtils . startsWithAny ( stackElemClassName , carePackages ) || StringUtils . startsWithAny ( stackElemClassName , exceptablePackages ) ) { continue ; } stackBuilder . append ( " [className=" ) . append ( stackElements [ i ] . getClassName ( ) ) . append ( ", fileName=" ) . append ( stackElements [ i ] . getFileName ( ) ) . append ( ", lineNumber=" ) . append ( stackElements [ i ] . getLineNumber ( ) ) . append ( ", methodName=" ) . append ( stackElements [ i ] . getMethodName ( ) ) . append ( ' ' ) . append ( Strings . LINE_SEPARATOR ) ; } stackBuilder . append ( "], full depth [" ) . append ( stackElements . length ) . append ( "]" ) ; LOGGER . log ( logLevel , stackBuilder . toString ( ) ) ; }
Prints call stack with the specified logging level .