Go
Send logs and errors from Go to LogNorth: an slog handler, HTTP middleware with trace IDs, and stack traces on errors.
go get github.com/karloscodes/lognorth-sdk-goQuick Start
Section titled “Quick Start”package main
import lognorth "github.com/karloscodes/lognorth-sdk-go"
func main() { lognorth.Config("https://logs.yoursite.com", "your-api-key")
lognorth.Log("User signed up", map[string]any{"user_id": 123}) lognorth.Error("Checkout failed", err, map[string]any{"order_id": 42})}Environments
Section titled “Environments”Config sends from every environment. To label events and keep development and test quiet, use Configure:
lognorth.Configure(lognorth.Options{ URL: os.Getenv("LOGNORTH_URL"), APIKey: os.Getenv("LOGNORTH_API_KEY"), Environment: os.Getenv("APP_ENV"), // stamped on every event as context.environment})With Configure, LogNorth sends nothing when Environment is development or test. Set Enabled to decide yourself.
With slog
Section titled “With slog”slog.SetDefault(slog.New(lognorth.NewHandler()))
slog.Info("User signed up", "user_id", 123)slog.Error("Checkout failed", "error", err)Middleware
Section titled “Middleware”http.HandleFunc("/", homeHandler)http.HandleFunc("/users", usersHandler)
http.ListenAndServe(":8080", lognorth.Middleware(http.DefaultServeMux))The middleware automatically:
- Generates a
trace_idper request (or usesX-Trace-IDfrom the incoming header) - Sets
X-Trace-IDon the response - Logs the request with
duration_msandtrace_idas top-level fields
Users and releases
Section titled “Users and releases”Name the signed-in user inside a handler. Use an ID, never an email:
lognorth.SetUser(r.Context(), strconv.Itoa(user.ID))The issue page then shows how many users an issue hit. Errors also carry the release, from Options.Release or from LOGNORTH_RELEASE, GIT_SHA, KAMAL_VERSION, or your host’s commit variable. At startup the SDK logs Release <version> started, and LogNorth draws each deploy as a dashed line on its charts.
Ignoring Routes
Section titled “Ignoring Routes”Skip health checks and other noisy endpoints:
lognorth.IgnorePaths("/healthz", "/_health", "/metrics")These paths won’t be logged by the middleware.
How It Works
Section titled “How It Works”| Method | Behavior |
|---|---|
Log() |
Batched (10 events or 5s) |
Error() |
Sent immediately with stack trace |
| Middleware | Logs requests with trace_id + duration_ms |
| Shutdown | Auto-flush on SIGINT/SIGTERM |
Error() automatically captures the error class, file, line, caller function, and full stack trace. LogNorth groups errors into issues by them.