Created
November 18, 2022 11:25
-
-
Save dln/66ee8b5e4b5bab35941825e709f0d9af to your computer and use it in GitHub Desktop.
structured logging in golang
This file contains 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
package main | |
import ( | |
"errors" | |
"os" | |
"golang.org/x/exp/slog" | |
) | |
func main() { | |
opts := slog.HandlerOptions{Level: slog.DebugLevel} | |
handler := opts.NewJSONHandler(os.Stderr) | |
log := slog.New(handler) | |
slog.SetDefault(log) | |
slog.Debug("debuggelibugg!") | |
slog.Info("här kommer mitt meddelande 🚀🚀🚀", "bar", 42, "tjosan", []int{1, 2, 3, 4}) | |
slog.Log(slog.InfoLevel+1, "Tjosan!") | |
slog.Warn("Varning varning! ⚠⚠⚠") | |
slog.Error("Nu sket nån i the blå skåpet! 🔥🔥🔥", errors.New("Blå skåpet är nedskitet")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://go.dev/play/p/M9Qm9HmL-Js