api-logger
@rtorcato/api-logger wraps pino with sensible defaults: pretty-printed output in development, structured JSON in production.
Install
pnpm add @rtorcato/api-logger
# Pretty output in dev requires pino-pretty:
pnpm add -D pino-pretty
Usage
import { createLogger } from '@rtorcato/api-logger'
const log = createLogger({ level: 'info' })
log.info('server started')
log.warn({ port: 3000 }, 'port already in use, retrying')
log.error({ err }, 'unhandled exception')
The returned logger is a standard pino.Logger — all pino methods work.
Dev vs production
| Environment | Output | Requires |
|---|---|---|
NODE_ENV !== 'production' | Pretty-printed, coloured | pino-pretty (dev dep) |
NODE_ENV === 'production' | Structured JSON | nothing extra |
Override with the pretty option:
// Force pretty regardless of NODE_ENV
const log = createLogger({ pretty: true })
// Force JSON in dev
const log = createLogger({ pretty: false })
Log level
Priority order:
options.level(explicit argument)process.env.LOG_LEVEL'info'(default)
// From env (wired with api-config):
const log = createLogger({ level: env.LOG_LEVEL })
Custom destination
Pass a pino destination stream for tests or custom sinks (overrides pretty):
import { createLogger } from '@rtorcato/api-logger'
import { pino } from 'pino'
const dest = pino.destination('/var/log/app.log')
const log = createLogger({}, dest)