You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.5 KiB

  1. [![GoDoc](https://godoc.org/github.com/go-stack/stack?status.svg)](https://godoc.org/github.com/go-stack/stack)
  2. [![Go Report Card](https://goreportcard.com/badge/go-stack/stack)](https://goreportcard.com/report/go-stack/stack)
  3. [![TravisCI](https://travis-ci.org/go-stack/stack.svg?branch=master)](https://travis-ci.org/go-stack/stack)
  4. [![Coverage Status](https://coveralls.io/repos/github/go-stack/stack/badge.svg?branch=master)](https://coveralls.io/github/go-stack/stack?branch=master)
  5. # stack
  6. Package stack implements utilities to capture, manipulate, and format call
  7. stacks. It provides a simpler API than package runtime.
  8. The implementation takes care of the minutia and special cases of interpreting
  9. the program counter (pc) values returned by runtime.Callers.
  10. ## Versioning
  11. Package stack publishes releases via [semver](http://semver.org/) compatible Git
  12. tags prefixed with a single 'v'. The master branch always contains the latest
  13. release. The develop branch contains unreleased commits.
  14. ## Formatting
  15. Package stack's types implement fmt.Formatter, which provides a simple and
  16. flexible way to declaratively configure formatting when used with logging or
  17. error tracking packages.
  18. ```go
  19. func DoTheThing() {
  20. c := stack.Caller(0)
  21. log.Print(c) // "source.go:10"
  22. log.Printf("%+v", c) // "pkg/path/source.go:10"
  23. log.Printf("%n", c) // "DoTheThing"
  24. s := stack.Trace().TrimRuntime()
  25. log.Print(s) // "[source.go:15 caller.go:42 main.go:14]"
  26. }
  27. ```
  28. See the docs for all of the supported formatting options.