logging-best-practices · aj-geddes — Claude Code skill: structured logs
A skill for setting up logging: levels, JSON output, context fields, PII handling and centralized collection.
npx skills add aj-geddes/useful-ai-prompts --skill logging-best-practices -a claude-codeWhat logging-best-practices does
The skill walks through application logging: DEBUG, INFO, WARN, ERROR and FATAL levels, structured JSON output, context fields like userId and requestId, PII handling and centralized collection. It ships a short TypeScript logger example plus eight reference files under references/: log levels, JSON, contextual logging, PII, performance, centralized logging, distributed tracing and sampling for high-volume services.
There is a do-and-don't list too. It advises against console.log in production, logging passwords or tokens, leaving DEBUG on by default, and skipping log rotation — the disk fills up. For hot paths it points to async logging and sampling.
The skill earns its place when logs exist but searching them hurts. Install runs through npx skills add with a platform flag: -a claude-code for Claude, -a codex for Codex, -a cursor for Cursor. The skill file lands in the platform directory, such as ~/.claude/skills/logging-best-practices/SKILL.md.
What it helps with
- split logs into levels and drop DEBUG from production
- move output from strings to JSON fields
- attach a request ID to every entry
- strip passwords and personal data from logs
- set up rotation and centralized collection
Example prompts for the agent
- set up structured logging in this service using the logging-best-practices skill
- audit my logger for PII leaks and tell me what to redact
- add requestId to logs and sampling for the high-traffic endpoint
How to install logging-best-practices
1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill logging-best-practices -a claude-code2Manually: put the files in place
~/.claude/skills/logging-best-practices/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/logging-best-practices/
1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill logging-best-practices -a codex2Manually: put the files in place
.agents/skills/logging-best-practices/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill logging-best-practices -a cursor2Manually: put the files in place
.cursor/skills/logging-best-practices/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install aj-geddes/useful-ai-prompts logging-best-practices2Manually: put the files in place
.github/skills/logging-best-practices/SKILL.md1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill logging-best-practices -a gemini-cli2Platform CLI
gemini skills install https://github.com/aj-geddes/useful-ai-prompts --path skills/logging-best-practicesManually: put the files in place
.devin/skills/logging-best-practices/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill logging-best-practices -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about logging-best-practices
How do I install logging-best-practices in Claude?
Run npx skills add aj-geddes/useful-ai-prompts --skill logging-best-practices -a claude-code. The skill ends up at ~/.claude/skills/logging-best-practices/SKILL.md.
What does logging-best-practices do?
It helps set up logging: levels, JSON format, context fields, PII protection and centralized collection. It includes a TypeScript logger example and reference files for each topic.
Which platforms does the skill support?
Besides Claude it installs into Codex, Cursor, GitHub Copilot, Gemini CLI and OpenCode, each with its own install command.
Source text
SKILL.md · MIT
---
name: logging-best-practices
description: >
Implement structured logging with JSON formats, log levels (DEBUG, INFO, WARN,
ERROR), contextual logging, PII handling, and centralized logging. Use for
logging, observability, log levels, structured logs, or debugging.
---
# Logging Best Practices
## Table of Contents
- [Overview](#overview)
- [When to Use](#when-to-use)
- [Quick Start](#quick-start)
- [Reference Guides](#reference-guides)
- [Best Practices](#best-practices)
## Overview
Comprehensive guide to implementing structured, secure, and performant logging across applications. Covers log levels, structured logging formats, contextual information, PII protection, and centralized logging systems.
## When to Use
- Setting up application logging infrastructure
- Implementing structured logging
- Configuring log levels for different environments
- Managing sensitive data in logs
- Setting up centralized logging
- Implementing distributed tracing
- Debugging production issues
- Compliance with logging regulations
## Quick Start
Minimal working example:
```typescript
// logger.ts
enum LogLevel {
DEBUG = 0, // Detailed information for debugging
INFO = 1, // General informational messages
WARN = 2, // Warning messages, potentially harmful
ERROR = 3, // Error messages, application can continue
FATAL = 4, // Critical errors, application must stop
}
class Logger {
constructor(private minLevel: LogLevel = LogLevel.INFO) {}
debug(message: string, context?: object) {
if (this.minLevel <= LogLevel.DEBUG) {
this.log(LogLevel.DEBUG, message, context);
}
}
info(message: string, context?: object) {
if (this.minLevel <= LogLevel.INFO) {
this.log(LogLevel.INFO, message, context);
}
}
warn(message: string, context?: object) {
// ... (see reference guides for full implementation)
```
## Reference Guides
Detailed implementations in the `references/` directory:
| Guide | Contents |
|---|---|
| [Log Levels](references/log-levels.md) | Log Levels |
| [Structured Logging (JSON)](references/structured-logging-json.md) | Structured Logging (JSON) |
| [Contextual Logging](references/contextual-logging.md) | Contextual Logging |
| [PII and Sensitive Data Handling](references/pii-and-sensitive-data-handling.md) | PII and Sensitive Data Handling |
| [Performance Logging](references/performance-logging.md) | Performance Logging |
| [Centralized Logging](references/centralized-logging.md) | Centralized Logging |
| [Distributed Tracing](references/distributed-tracing.md) | Distributed Tracing |
| [Log Sampling (High-Volume Services)](references/log-sampling-high-volume-services.md) | Log Sampling (High-Volume Services) |
## Best Practices
### ✅ DO
- Use structured logging (JSON) in production
- Include correlation/request IDs in all logs
- Log at appropriate levels (don't overuse DEBUG)
- Redact sensitive data (PII, passwords, tokens)
- Include context (userId, requestId, etc.)
- Log errors with full stack traces
- Use centralized logging in distributed systems
- Set up log rotation to manage disk space
- Monitor log volume and costs
- Use async logging for performance
- Include timestamps in ISO 8601 format
- Log business events (user actions, transactions)
- Set up alerts for error patterns
### ❌ DON'T
- Log passwords, tokens, or sensitive data
- Use console.log in production
- Log at DEBUG level in production by default
- Log inside tight loops (use sampling)
- Include PII without anonymization
- Ignore log rotation (disk will fill up)
- Use synchronous logging in hot paths
- Log to multiple transports without need
- Forget to include error stack traces
- Log binary data or large objects
- Use string concatenation (use structured fields)
- Log every single request in high-volume APIs
© aj-geddes · MIT · aj-geddes/useful-ai-prompts
Similar skills
Everything for DevOps and infrastructure →logging-best-practices by other authors comes first.