Skip to content

Logger

Overview

The logger is a Pino-based structured logger configured with both console and rotating file transports. It is pre-configured with the framework's log level and service name, and handles uncaught exceptions and promise rejections.

Logger Utility

ts
import { logger } from "@/framework/facade.js";

The logger is a Pino instance with a compat (message, meta) call signature:

MethodPurpose
logger.debug(msg, meta?)Detailed debugging information
logger.info(msg, meta?)General operational messages
logger.warn(msg, meta?)Warning conditions
logger.error(msg, meta?)Error conditions (also logged to fatal.log)
logger.fatal(msg, meta?)Critical errors (exits process after logging)
logger.trace(msg, meta?)Fine-grained trace information
logger.child(bindings)Create a child logger with added context

Usage

ts
import { logger } from "@/framework/facade.js";

logger.info("Server started", { port: env.APP_PORT });
logger.error("Failed to connect", { error: err.message });

const child = logger.child({ module: "auth" });
child.info("User logged in", { userId: 42 });

Transports

TransportLevelFileDetails
Consolematches level configColorized output with timestamp
Fileinfosrc/storage/logs/app.logRotating, max 10MB per file, 5 files
Fileerrorsrc/storage/logs/fatal.logRotating, max 10MB per file, 3 files, handles exceptions & rejections

Configuration

Logging settings are in src/config/logging.ts:

SettingDefaultDescription
level"info"Minimum log level (debug, info, warn, error, fatal, trace)
httpRequeststrueLog per-request HTTP access lines

Released under the MIT License.