Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here

stack

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

Subscribe to updates I use stack


Statistics on stack

Number of watchers on Github 95
Number of open issues 0
Main language Go
Average time to merge a PR 3 days
Open pull requests 0+
Closed pull requests 0+
Last commit over 3 years ago
Repo Created over 5 years ago
Repo Last Updated over 1 year ago
Size 13 KB
Organization / Authorfacebookgo
Contributors2
Page Updated
Do you use stack? Leave a review!
View stack activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating stack for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

stack

-- import github.com/facebookgo/stack

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.

The package provides stack.Multi which represents a sequence of stack traces. Since in Go we return errors they don't necessarily end up with a single useful stack trace. For example an error may be going thru a channel across goroutines, in which case we may want to capture a stack trace in both (or many) goroutines. stack.Multi in turn is made up of stack.Stack, which is a set of stack.Frames. Each stack.Frame contains the File/Line/Name (function name). All these types implement a pretty human readable String() function.

The GOPATH is stripped from the File location. Look at the StripGOPATH function on instructions for how to embed to GOPATH into the binary for when deploying to production and the GOPATH environment variable may not be set. The package name is stripped from the Name of the function since it included in the File location.

Usage

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.

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 {
}

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.

stack questions on Stackoverflow (View All Questions)
  • Strange Login error causes server to crash - AngularJS / MEAN stack
  • devstack installation - /opt/stack/keystone/bin/keystone-manage: No such file or directory
  • Looking for an Angular2 MEAN Stack
  • Bad type on the operand stack in arraylength
  • C3js stacked Area-Spline chart won't stack
  • What tool is used to generate this stack trace for Ruby grape?
  • ServiceNow Stack Overflow Error
  • Override back button in navigation stack
  • Failing to write post request in MEAN stack app
  • Using gitfs_remotes and Salt Stack formulas to provision Vagrant VM
  • Given the state of the stack and registers, can we predict the outcome of printf's undefined behavior
  • Dynamic html form generation in MEAN stack
  • Parent stack and backstack list in taskstack builder
  • View stack cookie protection in debugger
  • Why does LIFO (stack) memory exist, in a hardware context?
  • Cloudformation how to reference Managed-Policy from another stack
  • Deploy Yeoman full-stack app with Apache2 Reverse Proxy?
  • How does the undo stack work for gimpfu plugins?
  • Bug in GDB "layout src" showing corruption, data from previous stack frames
  • Expand UITableView to show all cells in Stack View?
  • Dockerize a full-stack Jenkins Slave server
  • Android: Increase call stack size
  • My ul menu, with links attached to the li tags, won't stack horizontally but goes vertical instead
  • Uncaught RangeError: Maximum call stack size exceeded and an Uncaught TypeError
  • XCode: Stack view and constraints
  • Disabling the stack smashing protection and Non-executable stack in Android.mk file
  • Stack memory layout in c
  • I want to learn complete MEAN stack technology from scratch. How can I learn?
  • Stack horizontal from right to left
  • Is it possible to change the stack size in Unity3d?
stack list of languages used
Other projects in Go