Skip to main content
skill CX Codex

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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add aj-geddes/useful-ai-prompts --skill logging-best-practices -a claude-code
Open on GitHub

What 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-code

2Manually: put the files in place

~/.claude/skills/logging-best-practices/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/logging-best-practices/

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.

logging-best-practices boristane This skill guides your agent to implement wide events (canonical log lines) instead of scattered logs. It consolidates request metrics, business context, and errors into one JSON event. CX Codex +1 4,800installs logging-best-practices Mindrally A skill that spells out logging rules: structured JSON, log levels, shared fields and request context. Useful when every service logs its own way. CX Codex +1 791installs logging-best-practices secondsky A skill that tells your agent how to log: levels, request context, PII masking. Useful when logs bloat or passwords end up in them. CX Codex +1 396installs review-logging-patterns HugoRCD The skill audits logging in a TypeScript codebase, flags console.log spam and context-free errors, and suggests moving to evlog. CX Codex +1 750installs logging codewithmukesh A .NET 10 observability skill: splits liveness from readiness, wires correlation IDs, and sets log levels. CX Codex +1 2,800installs go-logging cxuu A skill that steers your coding agent toward sane Go logging: slog, levels, structured fields, request-scoped context. Useful once a Go service grows more log lines than anyone reads. CX Codex +1 1,000installs cloudflare-workers-observability secondsky A skill for Cloudflare Workers observability: structured logging, Analytics Engine, Tail Workers, metrics and alerting. Useful when a worker fails in production and you can't see why. CX Codex +1 302installs audit-logging devops-skills A skill for setting up centralized audit logging, retention and SIEM forwarding. Useful when you need an action trail for compliance or incident review. CX Codex +1 385installs

From the same set118

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor