Skip to content

Logging

The logging module provides structured, leveled logging with pluggable transports. Log entries are plain objects — easy to forward to any log aggregation service.

Import

ts
import { createLogger } from '@loewen-digital/fullstack/logging'

Basic usage

ts
import { createLogger } from '@loewen-digital/fullstack/logging'

const logger = createLogger({ driver: 'console', level: 'info' })

logger.info('User logged in', { userId: 42 })
logger.warn('Rate limit approaching', { ip: '1.2.3.4', count: 95 })
logger.error('Payment failed', { orderId: 'ord_123', reason: 'insufficient_funds' })

Log levels

Levels follow the standard severity hierarchy. A configured level only emits that level and above.

LevelUse for
debugDetailed development diagnostics
infoNormal application events
warnRecoverable issues worth noting
errorFailures that need attention
fatalUnrecoverable errors

Child loggers

Create a child logger with pre-set context fields:

ts
const requestLogger = logger.child({ requestId: 'req_abc', userId: 7 })
requestLogger.info('Processing payment') // includes requestId and userId automatically

Driver options

DriverDescription
consolePretty-prints to stdout. Default for development.
fileAppends newline-delimited JSON to a log file.
httpPOSTs log batches to an HTTP endpoint (Logtail, Axiom, etc.).

Config options

OptionTypeDefaultDescription
driver'console' | 'file' | 'http''console'Transport driver
level'debug' | 'info' | 'warn' | 'error' | 'fatal''info'Minimum log level
file.pathstringPath to log file (file driver)
http.urlstringEndpoint URL (http driver)
http.headersRecord<string, string>{}Additional request headers