Structured Logging Rules

Structured Logging Rules

Gives an AI coding assistant a set of rules for structured JSON logging: fields, levels, trace IDs, redaction and testing of log output.

Structured Logging taste of a backend engineer who greps logs at 3 a.m.

  • Emit every log line as a single JSON object on stdout and let the platform ship it; never write log files from the app. Confidence: 0.90
  • Use the same core fields everywhere: timestamp, level, service, environment, version, message. Confidence: 0.90
  • Write timestamps in UTC as RFC 3339 with milliseconds, never in local time. Confidence: 0.95
  • Keep the message a short constant string and put variable data in fields, so "payment failed" stays searchable. Confidence: 0.90
  • Use only four levels in practice: debug, info, warn, error; error means someone should look at it. Confidence: 0.80
  • Set the log level from an environment variable and allow changing it at runtime without a redeploy. Confidence: 0.75
  • Attach trace_id and span_id from OpenTelemetry context to every line so logs join traces. Confidence: 0.90
  • Generate or accept a request_id at the edge, return it in a response header, and log it on every line for that request. Confidence: 0.90
  • Use a context-bound child logger (request, job, user) instead of passing ids into every log call. Confidence: 0.85
  • Log errors with error.type, error.message and error.stack as separate fields, not one interpolated string. Confidence: 0.85
  • Log an error once, where it is handled; do not log and rethrow at every layer. Confidence: 0.90
  • Never log secrets, tokens, passwords, full card numbers or session cookies; redact them in the logger, not by convention. Confidence: 0.95
  • Treat emails, phone numbers and IPs as personal data: hash or drop them unless there is a documented need. Confidence: 0.85
  • Write one canonical summary line per request with route, status, duration_ms and user or tenant id. Confidence: 0.80
  • Keep durations in a numeric field with the unit in its name (duration_ms), never as "1.2s" text. Confidence: 0.85
  • Follow a shared field naming scheme such as OpenTelemetry semantic conventions or ECS instead of inventing names per team. Confidence: 0.75
  • Sample noisy success logs (health checks, polling) and never sample errors. Confidence: 0.80
  • Use a fast structured logger with no reflection in hot paths: pino in Node, slog or zap in Go, structlog in Python. Confidence: 0.80
  • Pretty-print logs only in local development, behind an env flag, and keep production output raw JSON. Confidence: 0.85
  • Make logging non-blocking and bounded; dropping debug lines under pressure is better than stalling requests. Confidence: 0.70
  • Set retention per level and environment, for example 7 days for debug and 30 days for info and above. Confidence: 0.70
  • Alert on metrics derived from logs, not on single log lines, so one bad request does not page anyone. Confidence: 0.80
  • Add a test that asserts key log lines and their fields, so a refactor cannot silently break dashboards. Confidence: 0.65

Public domain (CC0 1.0) · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 6,373 prompts

More by @OpenSourceBuffGuy

See all
Website Clone Architect prompt image

Website Clone Architect

Reverse-engineers a website section by section, writes component specs, and hands them to parallel builder agents in git worktrees to rebuild it.

agent-skill, orchestrator, parallel-agents, multi-agent, plan-then-execute, web-development, frontend, codebase-analysis, scaffolding, css, html, nextjs, typescript, git, mcp, claude-code, for-developers, for-designers, long-form, advanced, technical-spec, task-decomposition, structured-output, design-systems, ui-ux, tool-use, checklist, report, vibe-coding

Italian Terrace Cafe Candid Portrait prompt image

Italian Terrace Cafe Candid Portrait

Generates a photorealistic candid shot of a woman in a white corset dress laughing at a sunny hotel terrace cafe, written as detailed JSON.

image-prompt, json-prompt, structured-output, photorealistic, portrait, woman, candid, fashion, cottagecore, natural-light, golden-hour, bokeh, summer, travel, cityscape, mountains, medium-shot, vibrant-colors, for-photographers, nano-banana, fashion-shoot, luxury

Night Street Photo With Leashed Cat prompt image

Night Street Photo With Leashed Cat

Generates a flash-lit night street photo of a blonde woman in a retro track jacket walking a hissing tabby cat on a leash.

image-prompt, json-prompt, nano-banana, structured-output, portrait, woman, animals, pet-portrait, night-scene, street-photography, candid, editorial, fashion, dramatic-lighting, photorealistic, vertical-format, medium-shot, graffiti, for-photographers, for-content-creators

1 view

Reviews

Loading reviews…

Discussion

Loading comments…