Skip to content
Back to skills

Logging Best Practices

ASecurity

Adds structured log lines with levels, correlation IDs and no personal data where they help. Use it when a service is hard to debug from its logs.

  • 3 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 15, 2026
ai-agentsapidatabase

Works with

  • cli
  • api

Security analysis

A100/100

Scanned November 15, 2026

npx -y skills add workspace-templates/ai-agent-templates --skill logging-best-practices --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Logging Best Practices?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Logging Best Practices
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/workspace-templates-logging-best-practices/badge)](https://www.skillsdirectory.com/skills/workspace-templates-logging-best-practices)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: logging-best-practices
description: Adds structured log lines with levels, correlation IDs and no personal data where they help. Use it when a service is hard to debug from its logs.
---

# Logging best practices

Log decisions and failures, not every step. Every line must help someone answer "what happened to this request?"

## Steps

1. Find the logger already in use (`grep -rn "logger\|logging\|pino\|winston\|slog" src`). Reuse it. Do not add a second library.
2. Locate the points that matter: request entry and exit, calls to other services and databases, retries, fallbacks, state changes, and every catch block.
3. Make sure a correlation ID exists. Read it from an incoming header such as `x-request-id` or create one at the edge, then attach it to the logger context so every line carries it.
4. Write each entry as structured key-value data with a short event name (`payment.declined`), not an interpolated sentence. Put variable data in fields.
5. Pick levels deliberately: ERROR only when someone should act, WARN for handled surprises, INFO for business events, DEBUG for detail that is off in production.
6. Log an error once, where it is handled, with the exception and stack. Do not log and rethrow at every layer.

## Never log

Passwords, tokens, API keys, session cookies, full card or national ID numbers, email addresses, or whole request bodies. Log an internal user ID or a masked value instead.

## Report

List the files changed, the events added with their levels, and any place where you found personal data already being logged.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.