How about groovy's StackTraceUtils.sanitize? Here's a quick example:
import org.codehaus.groovy.runtime.StackTraceUtils
class A {
def methodX() {
methodY()
}
def methodY() {
methodZ()
}
def methodZ() {
def marker = new Throwable()
StackTraceUtils.sanitize(marker).stackTrace.eachWithIndex { e, i ->
println "> $i ${e.toString().padRight(30)} ${e.methodName}"
}
}
}
new A().methodX()
The output of the above when pasted into a standalone script test.groovy
is as follows:
$ groovy test.groovy
> 0 A.methodZ(test.groovy:13) methodZ
> 1 A.methodY(test.groovy:9) methodY
> 2 A.methodX(test.groovy:5) methodX
> 3 A$methodX.call(Unknown Source) call
> 4 test.run(test.groovy:21) run
the sanitize method filters out all groovy internal mumbo jumbo from the trace and the clean trace together with ...stackTrace.find { }
should give you a decent start.