Skip to content

Guide · Open source

How to use pino: install, log JSON and add child loggers

Updated · written with AI from the project's own documentation and checked against our catalogue data

Pino is a JavaScript logging library that writes each log message as a single JSON object. This guide is for Node.js developers who want structured logs that are easy for software and log services to search and filter. By the end you will know how to install pino, write log messages, add context with child loggers and understand where transports and pino-pretty fit in.

pinopinojs/pino · ★ 18.3k · MIT

Quick start

  1. 1Install pino. Run npm install pino or yarn add pino in your Node.js project.
  2. 2Create a logger. Require pino and call it to get a logger instance.
  3. 3Log a message. Call logger.info with a string to write a JSON log line.
  4. 4Add a child logger. Use logger.child with an object to add fixed properties to later messages.
  5. 5Make logs readable in development. Install pino-pretty to format output while you work locally.
  6. 6Set up transports for production. Use pino.transport in a worker thread to send or reformat logs without blocking your app.

What pino is and when to use it

Pino is a logger for JavaScript, built to run on Node.js. Each log message is written as one JSON object, which makes logs easier to search and filter than plain text lines.

The README describes pino as very low overhead, meaning it is designed to add little cost to a running application. This matters most for web servers that handle many requests per second.

  • Good fit: Node.js backend services that need structured JSON logs.
  • Good fit: forwarding logs to other systems through transports.
  • Less suited: plain console output with no setup, since raw JSON is hard to read without a formatter.

Install pino with npm or yarn

Pino is installed with your package manager. The only listed prerequisite is Node.js.

npm install pino yarn add pino

Write your first log messages

Require pino, create a logger and call its methods such as info. The README example below produces one JSON line per message.

  • Each line includes fields such as level, time, msg, pid and hostname.
  • The level value is numeric in the README output (for example 30 for info).
const logger = require('pino')() logger.info('hello world') const child = logger.child({ a: 'property' }) child.info('hello child!')

Add context with child loggers

A child logger adds fixed properties to every message it writes. The README shows a child created with the property a set to 'property'; that property then appears in the child's log lines.

  • Create a child with logger.child(bindings).
  • Use child loggers to attach request or module context without repeating it at every call.

Format logs during development and use transports

The pino-pretty module formats logs so they are readable while you develop. For heavier work such as sending logs elsewhere or reformatting them, the README recommends running transports in a separate process or thread using the pino.transport API.

The README notes that Node's single-threaded event loop is the reason for this recommendation. The Transports document covers the details.

  • Development formatting: pino-pretty.
  • Log processing: pino.transport, run in a worker thread or separate process.
  • Web frameworks: the README links guides for Fastify, Express, Hapi, Restify, Koa, Node core http, Nest and Hono.

What people use it for

  • Logging every HTTP request in a Node.js web server with structured fields.
  • Adding a fixed property such as a module name to all messages from one part of an app using a child logger.
  • Forwarding JSON logs to another system through a transport.
  • Formatting logs with pino-pretty while developing on your own machine.

Frequently asked questions

How do I install pino?

Run npm install pino if you use npm, or yarn add pino if you use Yarn. The README lists Node.js as the prerequisite.

Is pino free to use?

Pino is released under the MIT licence, as stated in the README and the project's LICENSE file. Check the LICENSE file for the full terms.

Why does pino output look like raw JSON?

Pino writes each log as a JSON object by design. For readable output during development, use the pino-pretty module, which the README describes as a formatter for development.

Does pino work outside Node.js?

The README says pino is built to run on Node.js. It also mentions that pino works on Bare and Pear with the pino-bare compatibility module. It is not intended for non-JavaScript projects.

What are the alternatives to pino?

The README's comparable projects list Winston, Bunyan and Log4js. Compare them on the output format, performance and transport support for your project.

Does pino store or visualise logs?

No. Pino writes and routes logs but does not store or visualise them. You need a separate log management platform for that, and transports can send logs to other systems.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Pino suits Node.js backend developers who want fast, structured JSON logs and simple child loggers for context. It is a poor choice if you want readable console output with no setup, a non-JavaScript project, or a full log management platform out of the box.

Install options & downloads