$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
Monitoring & Loggingintermediate

Structured Logging

Share

Implement structured logging (Winston, Pino)

Works with OpenClaude

You are a Node.js logging engineer. The user wants to implement structured logging using either Winston or Pino to enable machine-readable log output with consistent formatting and metadata.

What to check first

  • Run npm list winston pino to see if either logging library is already installed
  • Check your Node.js version with node --version (both libraries support Node 12+)
  • Inspect your current logging calls to identify what metadata you're tracking (user IDs, request IDs, timestamps)

Steps

  1. Install Pino (lightweight, faster) with npm install pino or Winston with npm install winston
  2. Create a logger.js file to centralize logger configuration and exports
  3. Define a logging format that includes timestamp, level, message, and custom fields as key-value pairs
  4. Add transport configuration to write logs to stdout for development and file system for production
  5. Implement context middleware to attach request IDs and user metadata to every log entry
  6. Replace all console.log() calls with logger.info(), logger.error(), etc. with structured metadata as the second argument
  7. Configure log rotation for file transports to prevent disk space issues
  8. Test log output in JSON format by piping to jq to verify field accessibility

Code

// logger.js - Pino configuration for structured logging
import pino from 'pino';
import path from 'path';
import fs from 'fs';

const isDev = process.env.NODE_ENV !== 'production';

// Create logs directory if it doesn't exist
const logsDir = path.join(process.cwd(), 'logs');
if (!fs.existsSync(logsDir)) {
  fs.mkdirSync(logsDir);
}

const pinoConfig = {
  level: process.env.LOG_LEVEL || (isDev ? 'debug' : 'info'),
  timestamp: pino.stdTimeFunctions.isoTime,
};

const transports = isDev
  ? pino.transport({
      target: 'pino-pretty',
      options: {
        colorize: true,
        translateTime: 'SYS:standard',
        ignore: 'pid,hostname',
      },
    })
  : pino.transport({
      targets: [
        {
          level: 'info',
          target: 'pino/file',
          options: { destination: path.join(logsDir, 'app.log') },
        },
        {
          level: 'error',
          target: 'pino/file',
          options: { destination: path.join(logsDir, 'error.log') },
        },
      ],
    });

const logger = pino(pinoConfig, transports);

// Middleware to attach request context
export const requestLogger = (req, res, next) => {
  req.logger = logger.child({
    requestId: req.id || crypto.randomUUID

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
monitoringloggingstructured

Install command:

curl -o ~/.claude/skills/structured-logging.md https://claude-skills-hub.vercel.app/skills/monitoring/structured-logging.md

Related Monitoring & Logging Skills

Other Claude Code skills in the same category — free to download.

Want a Monitoring & Logging skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.