requestLog
constrequestLog: (config?) =>Policy
Defined in: src/policies/observability/request-log.ts:105
Emit structured JSON logs for every request/response pair.
Captures method, path, status, duration, client IP, user agent, and gateway context (request ID, gateway name, route path). Runs at priority 0 so it wraps the entire pipeline and measures end-to-end latency.
By default, logs are written to console.log as JSON lines. Provide a
custom sink to route logs to an external service (e.g., Logflare,
Datadog, or a Durable Object buffer).
Parameters
Section titled “Parameters”config?
Section titled “config?”Custom field extraction, body logging, and sink. All fields optional.
Returns
Section titled “Returns”A Policy at priority 0 (runs first, wraps everything).
Example
Section titled “Example”import { createGateway } from "@homegrower-club/stoma";import { requestLog } from "@homegrower-club/stoma/policies";
// Default structured JSON logging to consolecreateGateway({ policies: [requestLog()], routes: [...],});
// With body logging and redactionrequestLog({ logRequestBody: true, logResponseBody: true, redactPaths: ["password", "*.secret", "auth.token"], sink: async (entry) => { await fetch("https://logs.example.com/ingest", { method: "POST", body: JSON.stringify(entry), }); },});