Skip to content

Instantly share code, notes, and snippets.

@BolajiOlajide
Created December 30, 2024 01:55
Show Gist options
  • Save BolajiOlajide/e0c47d8af88399e2fc8c710e3b4d73db to your computer and use it in GitHub Desktop.
Save BolajiOlajide/e0c47d8af88399e2fc8c710e3b4d73db to your computer and use it in GitHub Desktop.
Go error stack with slog
func Error(val error) slog.Attr {
stack := make([]byte, 4096)
n := runtime.Stack(stack, false)
return slog.Group("error",
slog.String("exception.message", val.Error()),
slog.String("exception.stacktrace", fmt.Sprintf("%s", stack[:n])),
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment