Rails / Ruby:什么方法可以缩短堆栈跟踪?

时间:2021-01-07 02:03:51

I would like to limit the size of the stack traces I am seeing in Rails. I'm not really interested in debugging the Rails stack as much as my own application. Is there any built-in way to have Rails do this dynamically?

我想限制我在Rails中看到的堆栈跟踪的大小。我对调试Rails堆栈并不像我自己的应用程序那么感兴趣。是否有任何内置方法让Rails动态执行此操作?

2 个解决方案

#1


Yes. Take a look at the ActiveSupport::BacktraceCleaner class. Nice explanation here.

是。看一下ActiveSupport :: BacktraceCleaner类。这里的解释很好。

#2


You could wrap the code with your own exception catcher and just output how much you want.

您可以使用自己的异常捕获程序包装代码,并输出您想要的数量。

Using the array from the backtrace-Method

使用backtrace-Method中的数组

Only alternative I could think of. Recompiling Ruby and changing the values which control the stack depth in eval.c (TRACE_HEAD and TRACE_TAIL)

只有我能想到的替代方案。重新编译Ruby并更改控制eval.c中堆栈深度的值(TRACE_HEAD和TRACE_TAIL)

#1


Yes. Take a look at the ActiveSupport::BacktraceCleaner class. Nice explanation here.

是。看一下ActiveSupport :: BacktraceCleaner类。这里的解释很好。

#2


You could wrap the code with your own exception catcher and just output how much you want.

您可以使用自己的异常捕获程序包装代码,并输出您想要的数量。

Using the array from the backtrace-Method

使用backtrace-Method中的数组

Only alternative I could think of. Recompiling Ruby and changing the values which control the stack depth in eval.c (TRACE_HEAD and TRACE_TAIL)

只有我能想到的替代方案。重新编译Ruby并更改控制eval.c中堆栈深度的值(TRACE_HEAD和TRACE_TAIL)