← Back to archive

Repo of the Day

pinojs/pino

Published: Mar 6, 2023

Open repository ↗

🌲 super fast, all natural json logger

Summary

Pino is a JSON logger for Node.js focused on minimizing the overhead that logging adds to applications. It outputs structured JSON log lines, supports child loggers, and is designed so heavier log processing happens in a separate thread or process.

What it is useful for

Pino is useful in production Node.js services that emit JSON logs into a downstream pipeline and need consistent throughput as log volume grows. The README recommends running any sending, reformatting, or alerting work in a separate thread using its pino.transport API, which helps avoid blocking the main event loop. The same logging interface can also be used in development when paired with the separate pino-pretty module for human-readable output. Pino documents integrations with several web frameworks, including Fastify, Express, Hapi, Restify, Koa, Node core http, Nest, and Hono. Beyond Node.js, the README states Pino also runs on the Bare and Pear runtimes via a pino-bare compatibility module. Bundling for the browser is supported through tools like webpack and esbuild.

How engineers can use it

The README documents installation with npm or yarn:

$ npm install pino
$ yarn add pino

The documented basic usage is:

const logger = require('pino')()
logger.info('hello world')

const child = logger.child({ a: 'property' })
child.info('hello child!')

This emits two JSON objects containing level, time, msg, pid, hostname, and, for the child logger, the bound a property. For framework wiring, the README links to a Web Frameworks document covering each of the supported servers. For sending logs off-process, the Transports document covers pino.transport. For browser usage, redaction of sensitive fields, asynchronous logging configuration, and API options beyond what is shown above, the README directs readers to the linked Browser API, Redaction, Asynchronous Logging, and API documents; specific setup steps for those features are not included in the README itself, so consult those documents before configuring them.