Skip to content

Instantly share code, notes, and snippets.

@jcvenegas
Last active March 6, 2020 21:40
Show Gist options
  • Save jcvenegas/8e0279d55b8d1bfed3935054cec1e5ee to your computer and use it in GitHub Desktop.
Save jcvenegas/8e0279d55b8d1bfed3935054cec1e5ee to your computer and use it in GitHub Desktop.
Golang: Get stack printed via logrus (useful for logging in syslog)
// Kata runtime example:
// sudo journalctl -t kata-runtime -o json -f | jq .MESSAGE | grep DEBUG --color
import "runtime/debug"
func stackLogger(logger logrus.Entry) {
stack_bytes := debug.Stack()
stack := string(stack_bytes)
for _, l := range strings.Split(stack, "\n") {
logger.Warnf("DEBUG -> %s", l)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment