@shipfox/node-log
v0.3.0
Published
Typed logging for Node services built on top of `pino`, with consistent defaults, environment-driven configuration, and convenient helpers. It should be used with other packages from [Shipfox](https://www.shipfox.io/).
Keywords
Readme
Shipfox Log
Typed logging for Node services built on top of pino, with consistent defaults, environment-driven configuration, and convenient helpers. It should be used with other packages from Shipfox.
What it does
- log: Ready-to-use logger with levels
trace,debug,info,warn,error,fatal. - createLogger(options): Create a new
pinologger merging your options with Shipfox defaults. - settings: The default
pinoconfiguration used to buildlog(handy for extending). - Types re-exported:
Level,LogFn, andLoggerfor strong typing.
Defaults include:
- ISO timestamps
- Uppercased level labels (e.g.,
INFO,ERROR) - Standard serializers for
err,error,errors,req,res - Output formatting controlled via env: pretty printing or file output
Environment variables (via @shipfox/config):
LOG_LEVEL(default:info)LOG_PRETTY(default:false) — pretty print to stdout viapino-prettyLOG_FILE(default:undefined) — if set, logs to file usingpino/file(creates directory if needed)
Installation
pnpm add @shipfox/node-log
# or
yarn add @shipfox/node-log
# or
npm install @shipfox/node-logUsage
import { log, createLogger, settings, type Level } from "@shipfox/node-log";
// 1) Use the shared logger
log.info({ service: "billing" }, "Service started");
log.error({ err: new Error("boom") }, "Failed to process event");
// 2) Create a custom logger inheriting defaults
const moduleLogger = createLogger({
level: (process.env.LOG_LEVEL as Level) ?? settings.level,
base: { module: "payments" },
});
moduleLogger.debug({ eventId: "evt_123" }, "Processing payment event");
// 3) Environment-driven outputs
// - LOG_PRETTY=true prints colorized logs to stdout
// - LOG_FILE=/var/log/app.log writes JSON logs to a fileYou can combine LOG_PRETTY and LOG_LEVEL during development for readability.
