Structured Logging with slog #79

Open
opened 2026-02-23 10:07:24 +00:00 by ottomata · 0 comments
Owner

Tasks

  • Replace all fmt.Println, fmt.Printf, log.Printf usages with log/slog (Go standard library, 1.21+)
  • Configure logger in main.go:
    • Development (ENV=development): slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})
    • Production (ENV=production): slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})
    • Set as default: slog.SetDefault(logger)
  • Add contextual fields to key operations:
    • HTTP requests: request_id, method, path, status, duration_ms
    • Run events: run_id, job_id, status
    • Auth events: user_id, action
  • Never log passwords, tokens, or secrets
  • Update chi request logger middleware to use slog

Acceptance Criteria

  • All log output goes through slog — no raw fmt.Println remaining
  • JSON log output in production mode
  • Human-readable log output in development mode
  • run_id and job_id present in all run-related log entries
  • No sensitive data (tokens, passwords) appears in logs
### Tasks - [ ] Replace all `fmt.Println`, `fmt.Printf`, `log.Printf` usages with `log/slog` (Go standard library, 1.21+) - [ ] Configure logger in `main.go`: - Development (`ENV=development`): `slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})` - Production (`ENV=production`): `slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})` - Set as default: `slog.SetDefault(logger)` - [ ] Add contextual fields to key operations: - HTTP requests: `request_id`, `method`, `path`, `status`, `duration_ms` - Run events: `run_id`, `job_id`, `status` - Auth events: `user_id`, `action` - [ ] Never log passwords, tokens, or secrets - [ ] Update chi request logger middleware to use `slog` ### Acceptance Criteria - [ ] All log output goes through `slog` — no raw `fmt.Println` remaining - [ ] JSON log output in production mode - [ ] Human-readable log output in development mode - [ ] `run_id` and `job_id` present in all run-related log entries - [ ] No sensitive data (tokens, passwords) appears in logs
ottomata added this to the Phase 8 project 2026-02-23 10:09:19 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ottomata/acsm#79
No description provided.