stack

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package stack provides support for capturing stack traces efficiently.

It is a simplification of the zap package's internal implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Take

func Take(skip int) string

Take captures the current stack trace and returns its string representation.

skip is the number of frames before recording the stack trace with zero identifying the caller of Take.

Types

type Formatter

type Formatter struct {
	// contains filtered or unexported fields
}

Formatter is responsible for formatting a stack trace into a readable string representation.

func NewFormatter

func NewFormatter(buf *buffer.Buffer) Formatter

NewFormatter returns a new Formatter.

func (*Formatter) FormatFrame

func (f *Formatter) FormatFrame(frame runtime.Frame)

FormatFrame formats the given frame, appending it to the buffer.

func (*Formatter) FormatStack

func (f *Formatter) FormatStack(stack *Stack)

FormatStack formats all remaining frames in the given Stack (excl. final runtime.main/runtime.goexit frame), appending them to the buffer.

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

Stack is a captured stack trace.

A Stack is intended to be constructed via a sync.Pool using Capture.

func Capture

func Capture(skip int) *Stack

Capture captures a stack trace, skipping the given number of frames.

When skip is zero, this will identify the caller of Capture.

The caller must call Stack.Free on the returned Stack after using it to ensure that it's resources are released, and it's returned to a sync.Pool.

func (*Stack) Free

func (s *Stack) Free()

Free releases resources associated with the Stack and returns it to a sync.Pool.

Callers must not retain references to the Stack after calling Free.

func (*Stack) Len

func (s *Stack) Len() int

Len returns the number of frames in the Stack, however, it never changes if Next is called.

func (*Stack) Next

func (s *Stack) Next() (frame runtime.Frame, more bool)

Next returns the next frame in the Stack and a boolean indication of whether there are even more.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL