Structured JSON logging (stdlib only)¶
- One event per line (JSONL) emitted to stderr.
- Core fields:
timestamp,log.level,log.logger,event.name,message. - Error fields (ECS/OTel-friendly):
error.kind,error.message,error.stack. - Subprocess fields:
cmd,exit_code,process.duration_ms,output.stdout,output.stderr(truncated flags). - Configure level via
CODEX_LOG_LEVEL(defaultINFO).
References: Python logging/argparse/subprocess docs; OpenTelemetry Logs Data Model; Elastic Common Schema error fields.
Fallback metrics writer¶
- When
psutilorpynvmlare unavailable,src/logging_utils.setup_loggingnow initialises a JSONL fallback writer (enabled by default). - Metrics passed to
log_metrics(...)are appended toLoggingConfig.fallback_metrics_path(defaults to.codex/metrics/metrics_fallback.ndjson). - Each entry includes the log step, a floating-point timestamp, and the metric payload so observability pipelines retain minimal telemetry even without optional system libraries.