logger
Produces structured request/response log entries with method, URL, client IP, request ID, status code, and duration. Sensitive headers are automatically redacted. Place first in the pipeline so every subsequent middleware has a request ID available.
Pipeline stage: Negotiation (first middleware)
Import
Section titled “Import”import {logger} from '@centralping/ergo';Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
log |
function |
console.log |
Log function for completed requests |
error |
function |
console.error |
Log function for errors |
uuid |
function |
crypto.randomUUID |
Fallback UUID generator |
headerRequestIdName |
string |
'x-request-id' |
Request ID header name. Normalized to lowercase at construction for req.headers lookup (Node lowercases incoming header keys). Non-string values throw TypeError. |
headerRequestIpName |
string |
'x-real-ip' |
Client IP header name. Normalized to lowercase at construction (same rationale as headerRequestIdName). Non-string values throw TypeError. |
redactErrors |
boolean |
true |
When true, error log entries use generic HTTP status text instead of err.message, and suppress stack and originalError. Set to false in development for full error details. Independent of handler()’s redactErrors option (which controls HTTP response bodies). |
redactHeaders |
Set<string> |
See below | Headers replaced with '[REDACTED]' |
Default Redacted Headers
Section titled “Default Redacted Headers”authorization, proxy-authorization, cookie, set-cookie
Request ID Resolution Order
Section titled “Request ID Resolution Order”res.getHeader(headerRequestIdName)— set by ergo-router’s transportreq.headers[headerRequestIdName]— set by upstream proxyuuid()— generated as fallback
Return Value
Section titled “Return Value”Returns a log entry stored on the domain accumulator
at acc.log:
{ requestId: '550e8400-e29b-41d4-a716-446655440000', timestamp: 1717041600000, ip: '127.0.0.1', method: 'GET', url: '/users', httpVersion: '1.1', host: {hostname, arch, platform, pid}, request: {headers, encrypted, remoteAddress, remotePort}}On response finish, the log callback adds statusCode, duration,
and response: {headers, statusMessage, writableFinished}.
Error Responses
Section titled “Error Responses”None. Logger is observability-only.
import {compose, logger} from '@centralping/ergo';
const pipeline = compose( logger({ log: (info) => structuredLog.info(info), error: (info) => structuredLog.error(info), }),);const router = createRouter({ defaults: { logger: { log: (info) => structuredLog.info(info), }, },});RFC References
Section titled “RFC References”Related Recipes
Section titled “Related Recipes”- Structured Logging — Integrating pino or winston with the log callback and graceful() lifecycle logger
API Reference
Section titled “API Reference”See the auto-generated logger API docs.