Pino
- Node.js course
- Advanced
- Lesson 65/83
- 5 min
Learn high-performance logging with Pino.
Pino
Pino is a very high-performance logging library and an alternative to Winston. It is much faster than Winston because it writes logs asynchronously and adds minimal overhead. It is preferred in high-traffic systems.
Pino is not built in; install it with npm install pino. Create a logger with const pino = require("pino"); const logger = pino();. Pino writes JSON by default; structured logging is not an option, it is the default. The call logger.info({ user: "Ayşe" }, "Login") is written as JSON. Pino is 3-5 times faster than Winston, but less flexible in formatting. Pino is ideal for high-volume APIs where low latency matters.
Pino vs Winston
Pino and Winston have different design philosophies. Pino is speed-focused and makes JSON the default. Winston is flexibility-focused and supports multiple formats. Which one you choose depends on your needs.
In a high-traffic API where every millisecond matters, Pino is chosen. If you want to write logs to different files in different formats, Winston is more suitable. Pino writes logs as a JSON stream, which makes them easy to parse in search tools. Winston distributes logs to different destinations with transports. Both are mature and popular libraries. The choice depends on the answer to the performance vs flexibility question. Most production systems prefer Pino for speed.
Practice Create a Pino logger
Import the pino module. Create a logger with const logger = pino(). Log with logger.info("Pino ready").
Starter code
// Import the pino module
// write here
// Create a logger
// write here
// Write an info log
// write hereSample solution
const pino = require("pino");
const logger = pino();
logger.info("Pino ready");Expected output
Pino ready
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Complete the Pino logger call
const logger = ____();
const logger = pino();
Explanation: Write const logger = pino();.
2 Match each library to its trait
| Term | Meaning |
|---|---|
Pino |
Speed-focused |
Winston |
Flexibility-focused |
JSON |
Pino's default |
transport |
Winston's concept |
3 What is Pino's default log format?
logger.info({ user: "Ayşe" }, "Login")- HTML
- Plain text
- JSON Correct answer
- XML
Explanation: Pino writes JSON by default.