Automated summary
This skill walks through wiring Pino, the structured JSON logger for Node.js, covering a shared logger, secret redaction, pino-http middleware and child loggers.
Strengths
- Gives a complete logger.ts with level, base fields, redaction and an environment-conditional transport
- Flags the classic `err` pitfall: an Error logged under any other key serializes to `{}`
- Shows a realistic pino-http setup with customLogLevel, a success message and per-request `req.log` usage in handlers
- States that formatting, pretty-printing and shipping belong outside the request hot path
Limitations
- The content cuts off at Step 5, leaving the formatters, destinations and transports section unfinished
- No concrete shipping example for Datadog, Loki or Elasticsearch despite the description promising it
- Does not address testing, log rotation or benchmarking against other loggers
Reach for it when adding or replacing logging in a Node.js service (Express, Fastify, Next.js) with structured JSON logs that a log aggregator can parse.
Skip it for non-Node runtimes, or when what you actually need is a full tracing and metrics stack rather than a logger.
Security analysis
SafeThe skill is pure documentation for the Pino logging library: install commands for well-known npm packages (pino, pino-http, pino-pretty), TypeScript configuration snippets, and usage guidance. There are no destructive commands, no curl|sh pipes, no credential exfiltration, no obfuscated payloads, and no attempts to disable safety controls or override the auditor's role. The only 'execution' surface is a standard `npm install`, which is a normal, legitimate developer action.
No concerns found
How this analysis is madeExamples
Our Express API is full of console.log calls. Replace them with a single shared Pino logger that outputs JSON in production, pretty-prints in development, and redacts authorization headers and password fields.Add pino-http request logging to my Express app: one completion line per request with responseTime and a request id, error level for 5xx and warn for 4xx, and let handlers use req.log.Create a Pino child logger bound to a jobId and queue name so every log line in my invoice worker carries that context, and show how to log a caught error correctly.name: pino description: >- Pino is a fast Node.js logger that writes structured JSON, one object per line. Use when a user asks to add structured logging, replace console.log, configure log levels, redact secrets from logs, log HTTP requests in Express or Fastify, pretty-print logs in development, or ship logs to Datadog, Loki or Elasticsearch. license: Apache-2.0 compatibility: 'Node.js 20+ (pino 10 is tested on 20 and newer), Express, Fastify, Next.js' metadata: author: terminal-skills version: 1.1.0 category: devops repository: https://github.com/pinojs/pino tags: "pino, logging, nodejs, structured, observability"
Pino
Overview
Pino (current major version 10.x) is a low-overhead Node.js logger. Every call writes one line of JSON with a numeric level, a millisecond time, pid, hostname and your msg, which log aggregators (Datadog, Loki, Elasticsearch, CloudWatch) can parse without extra rules. Pino keeps work in the hot path small: formatting, pretty-printing and shipping are meant to happen outside the request path, in a worker-thread transport or in a separate process that reads stdout.
Companion packages: pino-http (request logging middleware, Express/Koa/Connect style), pino-pretty (human-readable output for development), pino-std-serializers (bundled; serializes err, req, res). Fastify has Pino built in: Fastify({ logger: true }).
Instructions
Step 1: Install
npm install pino pino-http
npm install -D pino-pretty
Step 2: Create one shared logger
// lib/logger.ts
import pino from "pino";
const isDev = process.env.NODE_ENV === "development";
export const logger = pino({
level: process.env.LOG_LEVEL ?? "info", // fatal, error, warn, info, debug, trace, silent
base: { service: "billing-api", version: process.env.npm_package_version },
redact: ["req.headers.authorization", "req.headers.cookie", "*.password", "*.apiKey"],
// JSON on stdout in production; pretty text only in development
transport: isDev ? { target: "pino-pretty", options: { colorize: true } } : undefined,
});
Usage: put the data object first, the message second.
logger.info({ port: 3000 }, "Server listening");
logger.warn({ latencyMs: 2500, endpoint: "/api/reports" }, "Slow request");
logger.error({ err, invoiceId: "inv_2041" }, "Payment capture failed"); // key must be "err"
An Error under the key err is serialized with type, message and stack. Logging it under another key (error, e) prints {} unless you add a serializer.
Step 3: Request logging with pino-http
import express from "express";
import pinoHttp from "pino-http";
import { logger } from "./lib/logger";
const app = express();
app.use(
pinoHttp({
logger,
customLogLevel: (req, res, err) =>
err || res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warn" : "info",
customSuccessMessage: (req, res) => `${req.method} ${req.url} ${res.statusCode}`,
}),
);
app.get("/orders/:id", (req, res) => {
req.log.info({ orderId: req.params.id }, "Loading order"); // child logger bound to this request
res.json({ id: req.params.id });
});
Every request gets an id and a completion line with responseTime. req.log already carries the request id, so use it inside handlers instead of the global logger.
Step 4: Child loggers for context
const jobLog = logger.child({ jobId: "job_7781", queue: "invoices" });
jobLog.info("Started"); // jobId and queue appear on every line
jobLog.info({ rows: 420 }, "Imported");
// {"level":30,"time":1790983327750,"service":"billing-api","jobId":"job_7781","queue":"invoices","rows":420,"msg":"Imported"}
Step 5: Levels as text, destinations, transports
- Numeric levels (30, 50) are the default. To print
"level":"info", useformatters: { level: (label) => ({ level: label }) }. This option cannot be combined withtransport.targets(multiple targets): Pino throwsoption.transport.targets do not allow custom level formatters. Use a singletargetor map levels in your aggregator. - Send logs to several places with
pino.transport({ targets: [...] }):
const transport = pino.transport({
targets: [
{ target: "pino/file", level: "error", options: { destination: "./logs/errors.log", mkdir: true } },
{ target: "pino-pretty", level: "info", options: { colorize: false } },
],
});
const logger = pino(transport);
- Transports run in a worker thread. For production, the simplest and most robust setup is plain JSON on stdout (
pino.destinationfor a file), collected by the platform (Docker, Kubernetes, systemd) or piped to a separate process. - Check cost before building expensive log data:
if (logger.isLevelEnabled("debug")) { ... }.
Examples
Example 1: Replace console.log in an Express API
User request: "Replace console.log with proper structured logging and make it quiet in tests."
Create lib/logger.ts as in Step 2 with level: process.env.LOG_LEVEL ?? "info", mount pinoHttp({ logger }), replace console.log("Started", port) with logger.info({ port }, "Started"), and run tests with LOG_LEVEL=silent npm test.
Result in production: {"level":30,"time":1790983316458,"service":"billing-api","port":3000,"msg":"Started"}; during tests nothing is printed.
Example 2: Keep secrets out of logs
User request: "Our request logs contain the Authorization header. Stop that."
const logger = pino({
redact: { paths: ["req.headers.authorization", "req.headers.cookie", "*.password"], censor: "[Redacted]" },
});
With pino-http, the logged request now shows "authorization":"[Redacted]". Use remove: true inside the redact object to drop the keys entirely.
Guidelines
- Log JSON in production, pretty text only in development; never ship
pino-prettyoutput to an aggregator. - Data first, message second; do not concatenate values into the message string.
- Use the key
errfor errors, and redact tokens, cookies and passwords withredact. - Create the logger once and import it; create child loggers per request or job.
- Do not set
formatters.leveltogether with multi-target transports, and do not format timestamps in-process (it costs throughput); let the aggregator do it. - Buffered destinations (
pino.destination({ sync: false })) can lose the last lines on a hard crash; keep the default synchronous stdout unless you have measured a need. - Log at the right level:
infofor business events,debugfor development detail,errorwhen someone should look.
From the file to a first result
The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.
View the source and supporting filesThis download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.
1. Download the file
Download SKILL.mdFrom the root of a test project, save the file as .skill-downloads/structured-logging-with-pino-for-node-js-mwirmdxl/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.
Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.
mkdir -p '.skill-downloads/structured-logging-with-pino-for-node-js-mwirmdxl' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/structured-logging-with-pino-for-node-js-mwirmdxl/download' --output '.skill-downloads/structured-logging-with-pino-for-node-js-mwirmdxl/SKILL.md.part' && mv '.skill-downloads/structured-logging-with-pino-for-node-js-mwirmdxl/SKILL.md.part' '.skill-downloads/structured-logging-with-pino-for-node-js-mwirmdxl/SKILL.md'2. Check prerequisites
Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.
Environment declared by the author: Node.js 20+ (pino 10 is tested on 20 and newer), Express, Fastify, Next.js
No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.
The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.
3. Load the skill
After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.
Claude Code
test -f '.skill-downloads/structured-logging-with-pino-for-node-js-mwirmdxl/SKILL.md' && test -s '.skill-downloads/structured-logging-with-pino-for-node-js-mwirmdxl/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/pino' && cp -R '.skill-downloads/structured-logging-with-pino-for-node-js-mwirmdxl' '.claude/skills/pino'Cursor
test -f '.skill-downloads/structured-logging-with-pino-for-node-js-mwirmdxl/SKILL.md' && test -s '.skill-downloads/structured-logging-with-pino-for-node-js-mwirmdxl/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/pino' && cp -R '.skill-downloads/structured-logging-with-pino-for-node-js-mwirmdxl' '.cursor/skills/pino'Codex
test -f '.skill-downloads/structured-logging-with-pino-for-node-js-mwirmdxl/SKILL.md' && test -s '.skill-downloads/structured-logging-with-pino-for-node-js-mwirmdxl/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/pino' && cp -R '.skill-downloads/structured-logging-with-pino-for-node-js-mwirmdxl' '.agents/skills/pino'OpenSkills
OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.
Official OpenSkills installationopenskills install './.skill-downloads/structured-logging-with-pino-for-node-js-mwirmdxl'openskills read 'structured-logging-with-pino-for-node-js-mwirmdxl'Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.
For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.
openskills syncManual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.
4. Try a first task
Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:
Read .skill-downloads/structured-logging-with-pino-for-node-js-mwirmdxl/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.
Configure a Chat Channel with SecretRefs
DevOps
Set up chat channels using non-interactive commands, with secrets only as SecretRefs. Covers gather, mutate, repair, and prove steps for reliable delivery.
Investigate ClickHouse CI Failures
DevOps
Investigate a ClickHouse CI failure end-to-end from a PR or S3 report URL. Fetches failed tests, classifies flaky vs real regression, and checks for existing issues/fixes.
Ansible PR Review
DevOps
Reviews an Ansible PR following the project's standardized process, including changelog checks, test coverage validation, and feedback tracking.