When the user is designing a logging approach for an application, reviewing existing log statements for quality, setting up log aggregation (ELK, Loki, CloudWatch), adding correlation IDs to a distributed system, or asking about what to log and what to avoid logging.
Rule of thumb: if you're unsure between two levels, pick the lower one. Over-logging at DEBUG is better than missing context at ERROR.
Always prefer structured logging (JSON or key-value pairs) over unstructured text:
User: "We have a REST API in Python and no structured logging. How should we set it up?"
Agent: Recommends replacing the stdlib
module's default formatter with
. Configures a processor chain that adds
,
,
,
, and outputs JSON. Adds middleware to generate and propagate a
for every incoming request. Sets up log level via environment variable (
for production,
for development). Refers to
references/structured-logging.md
for the structlog setup pattern.
User: "I'm logging user data for debugging, is this okay?"
Agent: Reviews the log statements and identifies PII exposure (email addresses, IP addresses logged at INFO level). Recommends masking emails (
), removing IP logging unless legally required, and moving detailed user data logging to DEBUG level with a note that DEBUG must never be enabled in production without a data processing agreement.
User: "Our logs are huge and costing us a fortune in storage."
Agent: Analyzes log volume by level and source. Identifies that health check endpoints generate 80% of INFO logs. Recommends: (1) reduce health check logging to DEBUG or sample at 1%, (2) move verbose middleware logs from INFO to DEBUG, (3) set retention to 14 days hot / 90 days cold, (4) add a
tag for high-frequency low-value events. Estimates 60-70% cost reduction.