Skip to content

Instantly share code, notes, and snippets.

@dln
Created November 18, 2022 11:25
Show Gist options
  • Save dln/66ee8b5e4b5bab35941825e709f0d9af to your computer and use it in GitHub Desktop.
Save dln/66ee8b5e4b5bab35941825e709f0d9af to your computer and use it in GitHub Desktop.
structured logging in golang
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"))
}
@dln
Copy link
Author

dln commented Nov 18, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment