Skip to content

Go

Add logging to Go apps using slog

Terminal window
go get github.com/lognorth/slog
import (
"log/slog"
"github.com/lognorth/slog/lognorth"
)
func main() {
slog.SetDefault(slog.New(lognorth.NewHandler()))
}
r := chi.NewRouter()
r.Use(lognorth.Middleware)
slog.Info("User signed up", "user_id", 123)
slog.Info("Payment failed", "user_id", 123, "error", "Card declined")