home / skills / oimiragieo / agent-studio / logging-module-usage

logging-module-usage skill

/.claude/skills/logging-module-usage

This skill guides developers to apply the logging module judiciously, logging important events, warnings, and errors for clear observability.

npx playbooks add skill oimiragieo/agent-studio --skill logging-module-usage

Review the files below or copy the command above to add this skill to your agents.

Files (12)
SKILL.md
1.5 KB
---
name: logging-module-usage
description: Employs the logging module judiciously to log important events, warnings, and errors.
version: 1.0.0
model: sonnet
invoked_by: both
user_invocable: true
tools: [Read, Write, Edit]
globs: '**/*.py'
best_practices:
  - Follow the guidelines consistently
  - Apply rules during code review
  - Use as reference when writing new code
error_handling: graceful
streaming: supported
---

# Logging Module Usage Skill

<identity>
You are a coding standards expert specializing in logging module usage.
You help developers write better code by applying established guidelines and best practices.
</identity>

<capabilities>
- Review code for guideline compliance
- Suggest improvements based on best practices
- Explain why certain patterns are preferred
- Help refactor code to meet standards
</capabilities>

<instructions>
When reviewing or writing code, apply these guidelines:

- **Logging:** Employ the `logging` module judiciously to log important events, warnings, and errors.
  </instructions>

<examples>
Example usage:
```
User: "Review this code for logging module usage compliance"
Agent: [Analyzes code against guidelines and provides specific feedback]
```
</examples>

## Memory Protocol (MANDATORY)

**Before starting:**

```bash
cat .claude/context/memory/learnings.md
```

**After completing:** Record any new patterns or exceptions discovered.

> ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.

Overview

This skill helps teams apply judicious logging in JavaScript projects using the logging module and equivalent libraries. It focuses on capturing important events, warnings, and errors without creating noisy or sensitive logs. The goal is reliable, actionable logs that aid debugging and monitoring while minimizing performance and privacy impact.

How this skill works

The skill reviews code to ensure log statements are meaningful, appropriately leveled, and placed at the right scope. It suggests improvements such as replacing console calls with structured logger usage, reducing verbosity, avoiding sensitive data in logs, and adding contextual metadata. It can also recommend refactors to centralize log configuration and consistent formatting.

When to use it

  • During code reviews to validate logging practices
  • When adding new features that require operational visibility
  • Before releases to ensure logs support debugging and SRE workflows
  • When migrating from console logging to a structured logging library
  • While designing error handling and alerting strategies

Best practices

  • Log at the correct level: debug for dev details, info for key events, warn for recoverable issues, error for failures requiring attention
  • Include contextual metadata (request id, user id, execution step) to make logs actionable
  • Avoid logging sensitive or PII data; redact or hash when necessary
  • Centralize logger configuration (formatters, transports, levels) to keep consistent output
  • Prefer structured logging (JSON or key/value) for easier parsing and alerting
  • Keep log volume reasonable: sample high-frequency events and avoid logging in tight loops

Example use cases

  • Audit a codebase to replace ad-hoc console.log with a structured logger
  • Refactor error handlers to emit standardized error events with stack and context
  • Create logger configuration that routes warning/error to monitoring and debug to local files
  • Improve observability by adding request and correlation IDs to service logs
  • Provide a checklist for safe logging before production deployments

FAQ

Should I log every exception?

Log exceptions that affect behavior or require investigation; don't log expected control-flow errors at error level—use warn or info as appropriate.

How do I handle sensitive fields in logs?

Redact or mask sensitive fields before logging, and limit full-data logs to secure environments with access controls.

When is structured logging necessary?

Use structured logging when logs are consumed by tools (ELK, Splunk, cloud logging) or when you need reliable parsing, filtering, and alerting.