stack

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2015 License: MIT Imports: 6 Imported by: 0

README

Documentation

Overview

Package stack provides utilities to capture and pass around stack traces.

This is useful for building errors that know where they originated from, to track where a certain log event occured and so on.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StripGOPATH

func StripGOPATH(f string) string

StripGOPATH strips the GOPATH prefix from the file path f. In development, this will be done using the GOPATH environment variable. For production builds, where the GOPATH environment will not be set, the GOPATH can be included in the binary by passing ldflags, for example:

GO_LDFLAGS="$GO_LDFLAGS -X github.com/facebookgo/stack.gopath $GOPATH"
go install "-ldflags=$GO_LDFLAGS" my/pkg

func StripPackage

func StripPackage(n string) string

StripPackage strips the package name from the given Func.Name.

Types

type Frame

type Frame struct {
	File string
	Line int
	Name string
}

Frame identifies a file, line & function name in the stack.

func Caller

func Caller(skip int) Frame

Caller returns a single Frame for the caller. The argument skip is the number of stack frames to ascend, with 0 identifying the caller of Callers.

func (Frame) String

func (f Frame) String() string

String provides the standard file:line representation.

type Multi

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

Multi represents a number of Stacks. This is useful to allow tracking a value as it travels thru code.

func CallersMulti

func CallersMulti(skip int) *Multi

CallersMulti returns a Multi which includes one Stack for the current callers. The argument skip is the number of stack frames to ascend, with 0 identifying the caller of CallersMulti.

func (*Multi) Add

func (m *Multi) Add(s Stack)

Add the given Stack to this Multi.

func (*Multi) AddCallers

func (m *Multi) AddCallers(skip int)

AddCallers adds the Callers Stack to this Multi. The argument skip is the number of stack frames to ascend, with 0 identifying the caller of Callers.

func (*Multi) Stacks

func (m *Multi) Stacks() []Stack

Stacks returns the tracked Stacks.

func (*Multi) String

func (m *Multi) String() string

String provides a human readable multi-line stack trace.

type Stack

type Stack []Frame

Stack represents an ordered set of Frames.

func Callers

func Callers(skip int) Stack

Callers returns a Stack of Frames for the callers. The argument skip is the number of stack frames to ascend, with 0 identifying the caller of Callers.

func (Stack) String

func (s Stack) String() string

String provides the standard multi-line stack trace.

Jump to

Keyboard shortcuts

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