Scripts2026年7月16日·1 分钟阅读

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.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
pino Overview
直接安装命令
npx -y tokrepo@latest install c22f6ed8-8135-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产