refactor: replace all unstructured log.Printf with structured slog JSON#102
refactor: replace all unstructured log.Printf with structured slog JSON#102dantonioluigi wants to merge 3 commits into
Conversation
|
Review of PR #102 — refactor: replace all unstructured log.Printf with structured slog JSON Overall: Good direction. Moving to structured logging is the right call for PCMI. The scope is broad and the mechanical migration is mostly solid. However, there are several material gaps that should be addressed before merging. Positives Issues that should be fixed
Recommendation This is a valuable refactor but needs: |
- Create internal/log package with shared JSON logger (Debug, Info, Warn, Error, Fatal) - Migrate 157+ log calls across 23 files to structured key-value format - Remove all emoji from log messages for log aggregator compatibility - Assign correct log levels per severity instead of flat Printf/Println - Add Mask helper for sensitive strings (DB URLs, keys)
9d32c52 to
b018f10
Compare
- Replace bare pointer with atomic.Pointer[slog.Logger] for safe concurrent SetLevel - Move os.Getenv out of log.go into config.Config (LogFormat, LogLevel, LogSource) to satisfy getenv audit invariant - Add Configure(format, level, addSource) hook wired to cmd/api, worker, migrate - TTY auto-detect: falls back to human-readable text handler when stdout is a terminal - Add *Context family (InfoContext, WarnContext, ErrorContext, DebugContext) that inject trace_id/span_id when an OTel span is active on the context - Add otelHandler wrapper on every slog.Handler for native trace correlation - Harden Mask(): URL credential redaction (user:pass@ → ***@), prefix+suffix truncation, clamp prefix 4–20, handle empty/short strings gracefully - Add 30 test cases covering Mask, level parsing, concurrent SetLevel, JSON/text output, env config, and context enrichment (all -race clean)
d82df99 to
19fc7f8
Compare
Summary
Type of change
Checklist
make test(andmake lintfor Go changes)make ci-like-githubor targeted job parity (make act-lint,make act-test,make act-integration-smoke) for CI-touching changes-tags=integrationwhere relevant)[Unreleased]if user-visibleinternal/version/version.go+docs/openapi.yaml+ HelmappVersionif releasing API version (smoke picks upTagautomatically)docs/grpc-vs-http.md/ SDKHTTP-API.mdupdated for API changesTest plan