Skip to content

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 {logger} from '@centralping/ergo';
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]'

authorization, proxy-authorization, cookie, set-cookie

  1. res.getHeader(headerRequestIdName) — set by ergo-router’s transport
  2. req.headers[headerRequestIdName] — set by upstream proxy
  3. uuid() — generated as fallback

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}.

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),
}),
);
  • Structured Logging — Integrating pino or winston with the log callback and graceful() lifecycle logger

See the auto-generated logger API docs.