Skill

structured-logging

Install
1
Install the plugin
$
npx claudepluginhub majesticlabs-dev/majestic-marketplace --plugin majestic-engineer

Want just this skill?

Add to a custom plugin, then install with one command.

Description

Production logging patterns for observability and incident debugging. Structured JSON logging, correlation IDs, context propagation, log levels, and performance. Use when implementing logging, adding observability, or debugging production systems. Triggers on logging setup, logger configuration, observability, distributed tracing, or incident response workflows.

Tool Access

This skill uses the workspace's default tool permissions.

Skill Content

Structured Logging

Core Philosophy

  • Logs are optimized for querying, not writing — design with debugging in mind
  • A log without correlation IDs is useless in distributed systems
  • If you can't answer "Who was affected? What failed? When? Why?" within 5 minutes, logging needs work

Structured Format

Always use key-value pairs (JSON), never string interpolation.

{
  "event": "payment_failed",
  "user_id": "123",
  "reason": "insufficient_funds",
  "amount": 99.99,
  "timestamp": "2025-01-24T20:00:00Z",
  "level": "error",
  "service": "billing",
  "request_id": "req_abc123"
}

Required Fields

Every log event MUST include:

FieldFormatExample
timestampISO 8601 with timezone2025-01-24T20:00:00Z
leveldebug, info, warn, errorinfo
eventsnake_case, past tenseuser_login_succeeded
request_id or trace_idUUID or prefixed IDreq_abc123
serviceService/app nameapi-gateway
environmentprod, staging, devprod

High-Cardinality Fields

Include these when available — they make logs queryable during incidents:

CategoryFields
Identityuser_id, org_id, account_id
Tracingrequest_id, trace_id, span_id
Domainorder_id, transaction_id, job_id

Rule: Look for domain-specific identifiers that help isolate issues to specific entities.

Log Levels

LevelWhen to UseExample
debugVerbose local dev details, disabled in prodVariable values, loop iterations
infoNormal operations worth recordingUser actions, job completions, deploys
warnUnexpected but handledRetries triggered, fallbacks activated
errorFailed, needs attentionExceptions, failed requests, timeouts

Anti-pattern: Don't log errors for expected conditions (wrong password = info, not error).

Context Propagation

For distributed systems:

  1. Inherit IDs — Downstream services must receive correlation IDs from upstream
  2. Pass through boundaries — HTTP headers, message queues, async jobs
  3. Middleware injection — Auto-inject context into every log via middleware/interceptor
[Client] --request_id--> [API Gateway] --request_id--> [Service A] --request_id--> [Service B]
                              |                              |                          |
                           (logs)                         (logs)                     (logs)
                              ↓                              ↓                          ↓
                     All queryable by single request_id

Async jobs: Store and restore original request context when processing background work.

What to Log

Log TheseSkip These
Request entry/exit with durationSensitive data (passwords, tokens, PII, cards)
State transitions (created → paid → shipped)Inside tight loops
External service calls with latency + statusSuccess cases with no debug value
Auth/authz eventsRedundant infra logs (LB already captures)
Job starts, completions, failures
Retry attempts, circuit breaker changes

Naming Conventions

PatternExample
Field names: snake_caseuser_id, not userId or user-id
Events: past tense verbspayment_completed, not complete_payment
Domain prefixes when helpfulauth.login_failed, billing.invoice_created

Team agreement: Define field names once, use consistently across all services.

Performance

ConcernSolution
High-volume debug logsSampling in production
Hot path loggingAvoid or use async appenders
I/O overheadBuffer and batch writes
Dynamic verbosityRuntime-configurable log levels

Language-Specific Implementations

LanguageLibraryNotes
PythonstructlogSee majestic-data/etl-core-patterns
Ruby/RailsRails.event (8.1+), semantic_loggerSee majestic-rails/dhh-coder/structured-events
Node.jspino, winston with JSON formatter
Goslog (stdlib), zerolog
Javalogback with JSON encoder

Decision Table: Log or Not?

ScenarioDecisionReason
User enters wrong passwordinfoExpected behavior, not an error
Payment gateway timeouterror + retryNeeds attention, affects user
Cache missdebugOnly useful for performance analysis
User created accountinfoBusiness event worth recording
Loop iteration 5000 of 10000Don't logCreates noise, no debug value
External API returns 500warn or errorDepends on retry/fallback behavior
Background job startedinfoUseful for job debugging
Background job failed after retrieserrorNeeds investigation

Incident Debugging Checklist

When designing logs, verify you can answer:

  • Who — Can filter to specific user/org/account?
  • What — Can identify the exact operation that failed?
  • When — Can narrow to specific time window?
  • Why — Is error context captured (reason, upstream cause)?
  • Where — Can trace across services via correlation ID?

Post-incident: Add the logs you wished you had.

Stats
Stars30
Forks6
Last CommitFeb 3, 2026
Actions

Similar Skills