Documentation
¶
Overview ¶
Package stacktrace provides utilities for capturing, representing, and formatting stack traces.
The package allows you to capture the current call stack, inspect stack frames, and render stack traces as human-readable strings.
Example:
stack := stacktrace.Capture(0, 10) fmt.Println(stack)
This captures up to 10 frames of the current stack and prints them in a readable format.
Index ¶
Constants ¶
const DefaultDepth = 64
DefaultDepth is the default maximum number of stack frames to capture.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack represents a captured stack trace as a sequence of frames.
Use the Capture function to obtain a Stack, and the String method to render it.
Example:
stack := stacktrace.Capture(0, 10) fmt.Println(stack)
func Capture ¶
Capture captures the current stack trace, skipping the specified number of frames and limiting the depth of the trace. If depth is math.MaxInt, it captures the full trace.
skip controls how many stack frames to skip (0 means start from the caller of Capture). depth limits the number of frames captured; use math.MaxInt for no limit.
Returns a *Stack containing the captured frames.
func (*Stack) AddCaller ¶
func (s *Stack) AddCaller()
AddCaller adds the current caller's frame to the stack.
func (*Stack) FramesIter ¶
FramesIter returns an iterator over the frames in the stack.
The iterator yields the frames starting from the most recent (the one added last).