Go
Add logging to Go apps
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})}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
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. These are used for three-tier issue grouping.