Skip to Content
OpenPerf

Conventions

Logging

How services write logs.

const log = logger.child({ module: "ingest-drainer" });

log.error({ table, err: error }, "Draining paused");
  • Log through pino, never console. Take logger from @openperf/server/logging and make one child per component, named in kebab-case: logger.child({ module: "ingest-drainer" }). In api, use Nest's Logger, but never its log() level.
  • Pass fields first and a static message second, with errors as err: log.error({ table, err: error }, "Draining paused").
  • A request writes one record when it ends. Add facts to it instead of logging again: PinoLogger.assign() in Nest apps, assignLogContext() in Bun apps. A failed request adds its error there as err.
  • A failed Postgres query is logged with its SQL text and without its values. Don't put values into log messages or error messages yourself.
  • Only an app's main.ts configures logging. Library code takes no logger and no callback that only logs.
  • Wrap pg-boss handlers in handleJobs from @openperf/server/postgres, so failures are logged once with their queue and jobId.
  • In tests, assert logs with recordLogs() from @openperf/server/logging/testing.