@orveth/logger

Structured logging contracts plus a reference ConsoleLogger that prints JSON lines to process.stdout. Swap the implementation in larger deployments while keeping the Logger interface stable across services.

LogLevel ordering

Levels follow ascending severity:

  1. trace
  2. debug
  3. info
  4. warn
  5. error
  6. fatal

The logger's configured minimum level filters outbound records. Messages below the threshold are discarded without side effects.

Logger interface

MethodSignature highlights
child(attributes)Returns a new logger merging baseline attributes into each record.
trace/debug/info/warn(message, attributes?)
error/fatal(message, attributes?, error?) — optional Error capture for stack metadata.

LogAttributes

Attributes are string-keyed maps whose values must be JSON-serializable primitives (string | number | boolean | null | undefined). Avoid embedding class instances or circular structures.

Example

logging/bootstrap.ts
import { ConsoleLogger } from "@orveth/logger";

export const log = new ConsoleLogger("info", {
  service: "payments",
  environment: process.env.NODE_ENV ?? "development",
});

export function logCheckout(durationMs: number) {
  log.info("checkout.completed", { durationMs });
}

export function logFailure(err: Error) {
  log.error("checkout.failed", { stage: "capture" }, err);
}