# pino — Super Fast Node.js Logger > Low-overhead JSON logger for Node.js that uses worker threads for transport, delivering 5x the throughput of alternatives. ## Install Save as a script file and run: # pino — Super Fast Node.js Logger ## Quick Use ```bash npm install pino ``` ```javascript const pino = require('pino'); const logger = pino({ level: 'info' }); logger.info({ user: 'alice' }, 'login successful'); logger.error({ err: new Error('timeout') }, 'request failed'); ``` ## Introduction pino is a low-overhead JSON logger for Node.js designed for production workloads. It achieves throughput 5x higher than alternatives like Winston and Bunyan by writing structured JSON to stdout and offloading formatting to separate transport processes. This design keeps the event loop free and logging fast. ## What pino Does - Outputs structured JSON logs to stdout with minimal serialization overhead - Supports standard log levels: trace, debug, info, warn, error, fatal - Offloads log transport and formatting to worker threads or child processes - Provides child loggers that inherit and extend parent context - Redacts sensitive fields like passwords and tokens from log output ## Architecture Overview pino writes newline-delimited JSON (NDJSON) to a file descriptor using synchronous writes that bypass the Node.js stream machinery. Formatting, filtering, and delivery to external systems happen in separate transport workers via `pino.transport()`, which runs in a worker thread with its own event loop. This architecture means logging never blocks the main application thread, even under high throughput. ## Setup & Configuration - Install via `npm install pino` and optionally `pino-pretty` for development formatting - Set the log level with `pino({ level: 'info' })` or the `LOG_LEVEL` environment variable - Use `pino.transport({ target: 'pino-pretty' })` for human-readable dev output - Configure redaction with `pino({ redact: ['password', 'token'] })` - Create child loggers with `logger.child({ requestId: 'abc' })` for per-request context ## Key Features - 5x faster than Winston and Bunyan in benchmarks - Worker-thread transports keep the event loop unblocked - Built-in field redaction for GDPR and security compliance - Child loggers with inherited context for request tracing - Ecosystem of 50+ community transports (Elasticsearch, Datadog, Loki, file rotation) ## Comparison with Similar Tools - **Winston** — pluggable transports in-process, pino offloads transports to workers for better performance - **Bunyan** — JSON-first like pino but slower; Bunyan CLI for viewing, pino uses pino-pretty - **Loguru (Python)** — similar philosophy of simple structured logging but for Python, not Node.js - **console.log** — no structure, no levels, no redaction; pino adds all of these with minimal overhead ## FAQ **Q: Why does pino output JSON instead of plain text?** A: JSON is machine-parseable, making it easy to ingest into log aggregation systems. Use `pino-pretty` for human-readable output during development. **Q: How do I send pino logs to Elasticsearch or Datadog?** A: Use a transport like `pino-elasticsearch` or `pino-datadog-transport` configured via `pino.transport()`. **Q: Can I use pino with Express or Fastify?** A: Yes. Fastify uses pino as its default logger. For Express, use `pino-http` middleware. **Q: Does pino support log rotation?** A: Use the `pino-roll` transport or pipe stdout to a rotation tool like `logrotate`. ## Sources - https://github.com/pinojs/pino - https://getpino.io --- Source: https://tokrepo.com/en/workflows/asset-c22f6ed8 Author: Script Depot