- Home
- Skills
- Andrelandgraf
- Fullstackrecipes
- Using Logging
using-logging_skill
- TypeScript
8
GitHub Stars
1
Bundled Files
3 weeks ago
Catalog Refreshed
2 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstart where the catalogue uses aiagentskills.
npx veilstart add skill andrelandgraf/fullstackrecipes --skill using-logging- SKILL.md3.4 KB
Overview
This skill teaches using structured logging with Pino across a TypeScript full-stack application. It focuses on log levels, attaching contextual data, and safe logging patterns for restricted workflow environments. The goal is consistent, searchable logs that help with debugging, monitoring, and incident response.
How this skill works
Instrument your app by importing a central logger and calling level-specific methods (trace, debug, info, warn, error, fatal). Always prefer structured logs: pass a context object first and a human message second. For workflows, use a small step wrapper that respects the runtime restrictions and forwards structured entries to the central logger.
When to use it
- Log business events and normal operations with info (e.g., user actions, job completion).
- Use debug or trace for development-only diagnostics and detailed troubleshooting.
- Emit warn for recoverable issues or impending deprecations.
- Record errors and stack traces with error; use fatal for unrecoverable app crashes.
- Wrap logging calls when running inside restricted workflow steps or sandboxed runtimes.
Best practices
- Always include a context object (userId, requestId, duration, endpoint) as the first argument for searchable structured logs.
- Use appropriate log levels and set LOG_LEVEL via environment variables to control verbosity per environment.
- Log durations and status codes for API routes to measure performance and failure patterns.
- Pass Error objects (or an err field) to error-level logs to preserve stack traces.
- Use a minimal, workflow-safe logger wrapper for steps to avoid violating runtime constraints.
Example use cases
- API route: log request start, duration, and final status to detect slow endpoints.
- Auth flows: log login attempts with userId and outcome at info or warn as appropriate.
- Background jobs: log job start, progress checkpoints, and errors with context for retries.
- Workflows: call a step-level log function to emit structured events from sandboxed workflow code.
- Prod debugging: switch LOG_LEVEL to debug temporarily to capture more diagnostic data.
FAQ
Use info as the default. Set LOG_LEVEL to debug or trace for development and to warn or error in production to reduce noise.
How should I include errors in logs?
Pass an Error object or an err field inside the context object to error-level logs so the logger can capture the stack trace and structured details.