Created
December 30, 2024 01:55
-
-
Save BolajiOlajide/e0c47d8af88399e2fc8c710e3b4d73db to your computer and use it in GitHub Desktop.
Go error stack with slog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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