Skip to content

commandCode quality

Add Logging

Adds structured log lines to one flow at the points that help debugging, with levels, context fields and no sensitive data.

npx workspacetemplates add add-logging --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/add-logging.md15 lines · 1.1 KBFile
---
description: Adds structured log lines to one flow at the points that help debugging, with levels, context fields and no sensitive data.
argument-hint: "[flow, function or file]"
---

Add structured logging to this flow: $ARGUMENTS

1. Find the project's logger (winston, pino, structlog, logging, slog, zap, log4j) and one well-logged file. Match its import, field names and level usage. If there is no logger, stop and ask before adding a dependency.
2. Trace the flow from entry to exit. Mark: start and end with duration, each external call, each branch that changes the outcome, retries, and every caught error.
3. Choose levels: debug for internals, info for business events, warn for recovered problems, error for failures with the cause attached.
4. Log fields, not sentences: request id, user id, order id, counts, elapsed ms. Reuse a correlation id if one exists.
5. Never log passwords, tokens, card numbers, full emails, request bodies or raw headers. Redact or log only an id.
6. No logging inside tight loops.

Show the diff plus a list of the lines added with their level. Run the tests. Ask before changing logger configuration.

What it does

Logs written in a panic are either silent when you need them or so chatty nobody reads them. This command traces one flow from entry to exit and picks the few places where a line will answer a real question later.

It uses the logger the project already has, adds fields instead of string concatenation, and keeps passwords, tokens and personal data out of every line.

Example

you › /add-logging the stripe webhook handler

agent › Added 7 lines in src/webhooks/stripe.ts: received (info, event id, type), signature failed (warn), duplicate event skipped (info), order updated (info, order id, ms), handler error (error with cause).
No payload or card data logged. 21 tests pass. Logger config untouched.

Questions

Which logger does it use?
The one already in the project. If none exists it asks before adding a package.
How does it avoid leaking private data?
It logs identifiers and counts only, and redacts anything that looks like a secret or personal field.
  • Add Error Handling

    CommandCode quality

    Free
  • Add Types

    CommandCode quality

    Free
  • Extract Function

    CommandCode quality

    Free
  • Find Dead Code

    CommandCode quality

    Free