Skip to main content
skill CX Codex

structured-logging-standardizer — Claude Code skill: how to install

structured-logging-standardizer sets up structured JSON logging with request correlation IDs using AsyncLocalStorage and pino. Keeps backend logs queryable and connected.

MIT 273 installs ★ 64 updated 2026-01-12

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add patricio0312rev/skills --skill structured-logging-standardizer -a claude-code
Open on GitHub

What structured-logging-standardizer does

This skill provides a standardized LogEntry interface for backend services. It defines core fields like timestamp, level, service, and environment, alongside tracing attributes including requestId, traceId, and userId.

It instructs the agent to inject an Express-style middleware that reads or generates the x-request-id header. Context is saved to AsyncLocalStorage, which the pino logger reads on every call. The guide explicitly forbids template string interpolation in favor of structured payload objects and snake_case metrics like duration_ms.

The code patterns target Node.js and TypeScript runtimes. Without AsyncLocalStorage support or outside the Node ecosystem, the middleware and logger wrapper must be adapted.

What it helps with

  • trace HTTP requests across log lines using x-request-id
  • establish a unified LogEntry JSON schema across backend endpoints
  • replace template string interpolation with structured metadata objects
  • store request and user context automatically via AsyncLocalStorage

Example prompts for the agent

  • Implement correlation ID middleware and a structured logger for our backend
  • Update error logging to follow the LogEntry schema with stack trace fields
  • Refactor string interpolation in log statements into structured context objects

How to install structured-logging-standardizer

1Skills CLI (Vercel)

npx skills add patricio0312rev/skills --skill structured-logging-standardizer -a claude-code

2Manually: put the files in place

~/.claude/skills/structured-logging-standardizer/SKILL.md

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

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about structured-logging-standardizer

How to install structured-logging-standardizer in Claude Code?

Run npx skills add patricio0312rev/skills --skill structured-logging-standardizer -a claude-code. You can also place the skill file directly at ~/.claude/skills/structured-logging-standardizer/SKILL.md.

What does structured-logging-standardizer do?

It instructs your AI assistant to generate standardized structured logs with correlation IDs. It includes a TypeScript schema, an Express middleware snippet, and rules against string interpolation.

Which libraries does this logging setup require?

The included implementation relies on pino for logging, uuid for ID creation, and Node.js AsyncLocalStorage for context propagation.

Source text

SKILL.md · MIT
---
name: structured-logging-standardizer
description: Enforces consistent structured logging with request correlation IDs, standardized log schema, middleware integration, and best practices. Use for "structured logging", "log standardization", "request tracing", or "log correlation".
---

# Structured Logging Standardizer

Implement consistent, queryable, correlated logs.

## Log Schema

```typescript
interface LogEntry {
  timestamp: string; // ISO 8601
  level: "debug" | "info" | "warn" | "error" | "fatal";
  message: string;
  service: string;
  environment: string;

  // Request context
  requestId?: string;
  traceId?: string;
  userId?: string;

  // Additional context
  [key: string]: any;
}
```

## Request ID Middleware

```typescript
import { v4 as uuidv4 } from "uuid";

app.use((req, res, next) => {
  // Generate or use existing request ID
  req.id = req.headers["x-request-id"] || uuidv4();

  // Add to response headers
  res.setHeader("x-request-id", req.id);

  // Store in async local storage
  asyncLocalStorage.run(new Map(), () => {
    asyncLocalStorage.getStore()?.set("requestId", req.id);
    next();
  });
});

// Logger with request context
const logger = pino({
  mixin() {
    return {
      requestId: asyncLocalStorage.getStore()?.get("requestId"),
    };
  },
});
```

## Standardized Logger

```typescript
class StandardLogger {
  private logger = pino();

  info(message: string, context?: Record<string, any>) {
    this.logger.info(
      {
        ...this.getContext(),
        ...context,
      },
      message
    );
  }

  error(message: string, error?: Error, context?: Record<string, any>) {
    this.logger.error(
      {
        ...this.getContext(),
        ...context,
        error: {
          message: error?.message,
          stack: error?.stack,
          name: error?.name,
        },
      },
      message
    );
  }

  private getContext() {
    return {
      requestId: asyncLocalStorage.getStore()?.get("requestId"),
      userId: asyncLocalStorage.getStore()?.get("userId"),
    };
  }
}
```

## Best Practices

```typescript
// ✅ DO: Structured fields
logger.info({ userId: '123', action: 'purchase', amount: 99.99 }, 'Purchase completed');

// ❌ DON'T: String interpolation
logger.info(\`User 123 purchased for $99.99\`);

// ✅ DO: Consistent field names
logger.info({ duration_ms: 150 }, 'Request completed');

// ❌ DON'T: Inconsistent naming
logger.info({ durationMs: 150 }, 'Request done');
```

## Output Checklist

- [ ] Request ID middleware
- [ ] Structured log schema
- [ ] Correlation IDs
- [ ] Standardized logger
- [ ] Best practices documented
      ENDFILE

© patricio0312rev · MIT · patricio0312rev/skills

Similar skills

All skills for Backend and APIs →

From the same set148

The whole set →
evaluation-harness evaluation-harness — a skill for Claude Code and five other agent platforms that sets up repeatable LLM evaluation: golden datasets, scoring rubrics, pass/fail thresholds, and regression reports. CX Codex +1 275installs backend-latency-profiler-helper backend-latency-profiler-helper tracks down slow API endpoints, lists likely causes, and puts the fixes in priority order. CX Codex +1 275installs rbac-policy-tester rbac-policy-tester generates role permission matrices and automated authorization test suites to catch RBAC regressions in CI. CX Codex +1 274installs etl-sync-job-builder etl-sync-job-builder generates TypeScript ETL pipelines with incremental watermark tracking, idempotent batch upserts, and retry backoff logic. CX Codex +1 274installs data-retention-archiving-planner data-retention-archiving-planner plans data retention policies, maps compliance requirements, and automates cold storage migration for databases. CX Codex +1 273installs reliability-strategy-builder reliability-strategy-builder builds a failure-handling plan for a service: circuit breaker, retries with backoff, fallback, bulkhead isolation and SLOs with error budgets. CX Codex +1 273installs e2e-test-builder e2e-test-builder generates end-to-end browser tests for Playwright and Cypress using Page Object patterns, test fixtures, and semantic selectors. CX Codex +1 273installs caching-strategy-optimizer The caching-strategy-optimizer skill configures CI/CD caching for dependencies, Docker layers, build outputs, and test results. Use it when installs, builds, or tests slow down the pipeline. CX Codex +1 272installs

Project sponsors

Companies that keep this analytics open