界面已本地化;技能介绍与说明文档按所选语言由 AI 自动翻译,代码、命令、路径和专业术语保留原文,以原作者文档为准。
探索技能
开发与工程 · SKILL.md

pino

pino

【开发与工程】Pino - extremely fast and low overhead Node.js logger with JSON-native structured logging. 10x faster than Winston. Optimized for high-performance APIs and production environments. USE WHEN: user mentions "pino", "fast logging", "high performance logging", "fastify logging", asks about "fastest node.js logger", "JSON structured logging", "low overhe…

独立 GitHub 快照 · 自动分类 · 以原作者文档为准

技能说明

GitHub

name: pino description: | Pino - extremely fast and low overhead Node.js logger with JSON-native structured logging. 10x faster than Winston. Optimized for high-performance APIs and production environments.

USE WHEN: user mentions "pino", "fast logging", "high performance logging", "fastify logging", asks about "fastest node.js logger", "JSON structured logging", "low overhead logging"

DO NOT USE FOR: Winston logging - use winston instead, Python logging - use python-logging instead, Complex transport requirements - use winston instead allowed-tools: Read, Grep, Glob, Write, Edit

Pino Logger - Quick Reference

When to Use This Skill

  • Structured logging in Node.js applications
  • High-performance logging
  • Integration with log aggregation systems

Deep Knowledge: Use mcp__documentation__fetch_docs with technology: pino for comprehensive documentation.

Basic Setup

npm install pino pino-pretty

Essential Patterns

Logger Base

import pino from 'pino';

const logger = pino({
  level: process.env.LOG_LEVEL || 'info',
  transport: {
    target: 'pino-pretty',
    options: { colorize: true }
  }
});

logger.info('Server started');
logger.error({ err }, 'Failed to connect');

Child Logger

const childLogger = logger.child({
  module: 'auth',
  requestId: req.id
});

childLogger.info({ userId }, 'User authenticated');

Express Integration

import pinoHttp from 'pino-http';

app.use(pinoHttp({ logger }));

Fastify Integration

import Fastify from 'fastify';

const fastify = Fastify({
  logger: {
    level: 'info',
    transport: {
      target: 'pino-pretty'
    }
  }
});

Production Configuration

const logger = pino({
  level: 'info',
  formatters: {
    level: (label) => ({ level: label }),
  },
  timestamp: pino.stdTimeFunctions.isoTime,
  base: {
    pid: process.pid,
    hostname: os.hostname(),
  },
});

When NOT to Use This Skill

  • Complex multi-transport requirements: Winston offers more flexible transport system
  • Custom log formatting beyond JSON: Winston has more formatting options
  • Development-only logging: Built-in console is simpler for quick debugging
  • Python/Java projects: Use language-specific logging frameworks
  • Legacy apps expecting text logs: Pino is JSON-first, requires parsing tools

Anti-Patterns

Anti-PatternWhy It's BadSolution
Using pino-pretty in production2-3x performance penaltyOnly use in development, raw JSON in prod
Logging large objectsSerialization overheadLog only necessary fields
Synchronous loggingDefeats Pino's async advantageUse default async mode, avoid pino.final()
Nested child loggers without cleanupMemory leak over timeReuse child loggers or clear references
Logging in hot paths without level checkStill has minimal overheadUse if (logger.isLevelEnabled('debug')) for extreme cases
Mixing multiple logger instancesInconsistent configurationCreate one base logger, use child loggers

Quick Troubleshooting

IssueCauseSolution
Unreadable JSON in consoleNo pretty-printer configuredAdd pino-pretty transport for development
Performance slower than expectedpino-pretty enabled in productionRemove pretty-printer, use raw JSON
Missing logsLevel too highCheck level configuration matches environment
Context not includedNot using child loggerUse logger.child({ context }) for request scoping
Logs not flushing on exitAsync logging bufferUse pino.final() or flush on SIGTERM
Extra fields not appearingIncorrect syntaxUse object as first param: logger.info({ field }, 'msg')
我的收藏