package httpserver import ( "log/slog" "net/http" "time" "github.com/gofiber/fiber/v2" "anchorage/internal/pkg/metrics" ) // accessLog is a minimal, slog-friendly request logger that also feeds // the Prometheus HTTP request counter. Full structured logging with // tenant + user attribution lives in the auth middleware once a JWT // is validated. // // /metrics itself is skipped — self-observing scrapes would show up as // a ton of 200s that tell the operator nothing. func accessLog() fiber.Handler { return func(c *fiber.Ctx) error { start := time.Now() err := c.Next() dur := time.Since(start) status := c.Response().StatusCode() lvl := slog.LevelInfo if status >= http.StatusInternalServerError { lvl = slog.LevelError } else if status >= http.StatusBadRequest { lvl = slog.LevelWarn } slog.Log(c.UserContext(), lvl, "http", "method", c.Method(), "path", c.Path(), "status", status, "duration_ms", dur.Milliseconds(), "request_id", c.Get(fiber.HeaderXRequestID), "remote", c.IP()) if c.Path() != "/metrics" { metrics.HTTPRequests. WithLabelValues(c.Method(), metrics.StatusClass(status)). Inc() } return err } }