如何打印Groovy堆栈跟踪? [英] How do I print a Groovy stack trace?
问题描述
如何打印Groovy堆栈跟踪? Java方法Thread.currentThread().getStackTrace()产生了巨大的堆栈跟踪,其中包括许多Groovy内部构件.我看到一个从StreamingMarkupBuilder调用过两次的函数,看起来应该只调用一次,而且我想看看为什么Groovy认为它应该调用两次.
How do I print a Groovy stack trace? The Java method, Thread.currentThread().getStackTrace() produces a huge stack trace, including a lot of the Groovy internals. I'm seeing a function called twice from a StreamingMarkupBuilder that looks like it should only be called once and I would like to see why Groovy thinks it should be calling it twice.
推荐答案
解决方案:
org.codehaus.groovy.runtime.StackTraceUtils.sanitize(new Exception()).printStackTrace()
原始答案:
Google搜索返回以下信息:
A Google search returns the following information:
显然,在org.codehaus.groovy.runtime.StackTraceUtils
中有一种称为printSanitizedStackTrace
的方法.尽管有一个名为sanitize
的方法,该方法描述为
Apparently, there is a method in org.codehaus.groovy.runtime.StackTraceUtils
called printSanitizedStackTrace
. There isn't much documentation for the method, though there is a method called sanitize
which is described as
删除所有明显的内部杂项 跟踪异常中的条目 实例修改原始 实例并返回它,它不会 克隆
remove all apparently groovy-internal trace entries from the exception instance This modifies the original instance and returns it, it does not clone
所以我会尝试org.codehaus.groovy.runtime.StackTraceUtils.printSanitizedStackTrace(Throwable t)
(它是静态的)
看看是否适合您.
So I would try org.codehaus.groovy.runtime.StackTraceUtils.printSanitizedStackTrace(Throwable t)
(it is static)
and see if that works for you.
这篇关于如何打印Groovy堆栈跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!