stackfmt

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: BSD-2-Clause Imports: 6 Imported by: 4

README

stackfmt

Golang. Create and format a stack trace. Useful for attaching stack traces to github.com/gregwebs/errors.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleFmtWriteError

func HandleFmtWriteError(handler func(err error))

HandleFmtWriteError handles (rare) errors when writing to fmt.State. It defaults to printing the errors.

Types

type Frame

type Frame uintptr

Frame represents a program counter inside a stack frame.

func (Frame) Format

func (f Frame) Format(s fmt.State, verb rune)

Format formats the frame according to the fmt.Formatter interface.

%s    source file
%d    source line
%n    function name
%v    equivalent to %s:%d

Format accepts flags that alter the printing of some verbs, as follows:

%+s   function name and path of source file relative to the compile time
      GOPATH separated by \n\t (<funcname>\n\t<path>)
%+v   equivalent to %+s:%d

type Stack

type Stack []uintptr

func NewStack

func NewStack() Stack

func NewStackSkip

func NewStackSkip(skip int) Stack

func (Stack) Format

func (st Stack) Format(s fmt.State, verb rune)

func (Stack) FormatStackTrace

func (st Stack) FormatStackTrace(s fmt.State, verb rune)

func (Stack) Frames

func (s Stack) Frames() []Frame

func (Stack) StackTrace

func (st Stack) StackTrace() StackTrace

type StackTrace

type StackTrace []Frame

StackTrace is stack of Frames from innermost (newest) to outermost (oldest).

func (StackTrace) Format

func (st StackTrace) Format(s fmt.State, verb rune)

Format formats the stack of Frames according to the fmt.Formatter interface.

%s	lists source files for each Frame in the stack
%v	lists the source file and line number for each Frame in the stack

Format accepts flags that alter the printing of some verbs, as follows:

%+v   Prints filename, function, and line number for each Frame in the stack.

func (StackTrace) FormatStackTrace

func (st StackTrace) FormatStackTrace(s fmt.State, verb rune)

type StackTraceFormatter

type StackTraceFormatter interface {
	FormatStackTrace(s fmt.State, verb rune)
}

StackTraceFormatter is an alternative to StackTracer that only uses standard library types In practice the stack trace is usually only used for printing. With this definition a package can define a printing of a stack trace without importing this package.

type StackTracer

type StackTracer interface {
	StackTrace() StackTrace
}

StackTracer retrieves the StackTrace

Jump to

Keyboard shortcuts

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