Stack trace as a string

2020-05-05 17:45发布

Is there any method to get a stack trace as a string?

Looking at the debug package (https://golang.org/pkg/runtime/debug/) it can only be printed to standard output.

标签: logging go
1条回答
叛逆
2楼-- · 2020-05-05 18:05

runtime.Stack() puts a formatted stack trace into a supplied []byte. You can then convert that to a string.

You can also use debug.Stack(), which allocates a large enough buffer to hold the entire stack trace, puts the trace in it using runtime.Stack, and returns the buffer ([]byte).

查看更多
登录 后发表回答