Request Logging
Automatic HTTP request metadata capture in logfmt format
uloki captures structured HTTP request metadata and formats it as logfmt lines for easy parsing in Grafana Loki.
Format
method=GET path=/api/users status=200 duration_ms=12 ua="Mozilla/5.0 ..."Labels include method, status, and level (info / warn / error) for filtering.
Log Levels
Automatically derived from status code:
| Status | Level |
|---|---|
| 200-399 | info |
| 400-499 | warn |
| 500+ | error |
API
fmtRequestLog(meta)
Build a structured log line from HTTP request metadata.
import { fmtRequestLog } from "uloki";
const line = fmtRequestLog({
method: "GET",
path: "/api/users",
status: 200,
durationMs: 12,
userAgent: "Mozilla/5.0",
});
// => "method=GET path=/api/users status=200 duration_ms=12 ua=\"Mozilla/5.0\""logRequest(logger, meta, extraLabels?)
Log an HTTP request with standard labels and auto-derived log level.
import { logRequest, LokiLogger } from "uloki";
const logger = new LokiLogger({ endpoint: "http://localhost:3100" });
logRequest(logger, {
method: "GET",
path: "/api/users",
status: 200,
durationMs: 5,
});
// Pushes: { line: "method=GET path=/api/users ...", labels: { method: "GET", status: "200", level: "info" } }Framework Integrations
Request logging is automatic in all framework integrations:
- Elysia — Automatically captures via
.onRequest+.onAfterResponse - Nitro — Hooks into
requestlifecycle - Nuxt — Wraps the Nitro plugin with
runtimeConfig.public.loki
No additional setup needed — it just works out of the box.