logging-best-practices

Standardize structured logging with Pino across Next.js routes and workflows.

20|3|Updated Nov 30, 2025
One-click install
npx skills add https://github.com/andrelandgraf/fullstackrecipes --skill logging-best-practices-andrelandgraf
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: logging-best-practices
Source: https://github.com/andrelandgraf/fullstackrecipes/tree/main/templates/fullstackrecipe/.agents/skills/logging-best-practices
Command: npx skills add https://github.com/andrelandgraf/fullstackrecipes --skill logging-best-practices-andrelandgraf

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Emit structured logs with Pino throughout the app to improve observability and debugging.

Core Features & Use Cases

  • Structured logging with levels (trace, debug, info, warn, error, fatal) across API routes and workflows
  • Context-first log signatures: pass a context object first, message second; attach errors via err in context
  • Workflow-safe logging: wrap logging calls inside a "use step" function so the runtime can't import Node modules

Quick Start

Install the logger and start emitting context-rich, level-based logs in routes, libraries, and workflows.

Frequently Asked Questions about logging-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement structured logging in Next.js API routes?

Structured logging in Next.js API routes is standardized by importing a centralized Pino logger and passing a context object first, then a message string. You use specific log levels like trace, debug, info, warn, error, and fatal to improve observability across development, staging, and production environments.

What is the best way to pass context and errors to Pino logs?

The best way to pass context and errors to Pino logs is using a context-first signature: provide a context object as the first argument and the message second. Attach errors within that context object using the err property to ensure proper structured output for debugging.

Can I use Node.js logging modules inside Next.js workflows?

You cannot directly import Node modules inside Next.js workflows. To use logging safely within workflows, wrap your logging calls inside a 'use step' function so the runtime can securely execute the logging logic without direct Node module imports.

Does this structured logging approach work across development, staging, and production?

Yes, this structured logging approach works across development, staging, and production environments. It applies standardized Pino logging with context-first signatures and specific log levels to server API routes and workflow steps throughout your entire Next.js application lifecycle.

Why use a centralized logger for Node.js observability?

You use a centralized logger for Node.js observability to standardize structured logs with Pino across all routes, libraries, and workflows. This enforces consistent context-first log signatures and specific levels, significantly improving debugging and application monitoring.