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";
OptionTypeDefaultDescription
logfunctionconsole.logLog function for completed requests
errorfunctionconsole.errorLog function for errors
uuidfunctioncrypto.randomUUIDFallback UUID generator
headerRequestIdNamestring'x-request-id'Request ID header name
headerRequestIpNamestring'x-real-ip'Client IP header name
redactHeadersSet<string>See belowHeaders 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 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),
}), "log"],
);
  • Structured Logging — Integrating pino or winston with the log callback and graceful() lifecycle logger

See the auto-generated logger API docs.