feat: replace log.Printf with structured slog logging #36

Merged
rodin merged 1 commits from feat/23-structured-logging into main 2026-05-02 18:07:13 +00:00
Owner

Summary

Replaces all bare log.Printf/log.Fatalf calls with Go stdlib log/slog structured logging.

Changes

  • New flags: --log-format (text/json) and --verbosity (debug/info/warn/error)
  • All log.Printfslog.Info/slog.Debug/slog.Warn with structured key-value attributes
  • All log.Fatalfslog.Error + os.Exit(1)
  • gitea/client.go warnings converted to slog.Warn
  • New tests for logger initialization, JSON/text output, and level filtering

Structured attributes used

pr, repo, verdict, findings, model, tokens, bytes, duration, error, file, event, review_id, user, comment_id, etc.

No third-party dependencies

Uses only log/slog from Go stdlib.

Closes #23
Partially addresses #32

## Summary Replaces all bare `log.Printf`/`log.Fatalf` calls with Go stdlib `log/slog` structured logging. ## Changes - **New flags:** `--log-format` (text/json) and `--verbosity` (debug/info/warn/error) - **All `log.Printf`** → `slog.Info`/`slog.Debug`/`slog.Warn` with structured key-value attributes - **All `log.Fatalf`** → `slog.Error` + `os.Exit(1)` - **`gitea/client.go`** warnings converted to `slog.Warn` - **New tests** for logger initialization, JSON/text output, and level filtering ## Structured attributes used `pr`, `repo`, `verdict`, `findings`, `model`, `tokens`, `bytes`, `duration`, `error`, `file`, `event`, `review_id`, `user`, `comment_id`, etc. ## No third-party dependencies Uses only `log/slog` from Go stdlib. Closes #23 Partially addresses #32
rodin added 1 commit 2026-05-02 18:02:10 +00:00
feat: replace log.Printf with structured slog logging
CI / test (pull_request) Successful in 14s
CI / review (gpt-4.1, gpt, GPT_REVIEW_TOKEN) (pull_request) Successful in 23s
CI / review (gpt-5, security, SECURITY_REVIEW.md, SECURITY_REVIEW_TOKEN) (pull_request) Successful in 52s
CI / review (gpt-5, sonnet, SONNET_REVIEW_TOKEN) (pull_request) Successful in 1m5s
d83ea4f726
- Add --log-format flag (text/json) and --verbosity flag (debug/info/warn/error)
- Replace all log.Printf with slog.Info/Debug/Warn with structured key-value attrs
- Replace all log.Fatalf with slog.Error + os.Exit(1)
- Convert gitea/client.go warnings to slog.Warn
- Add comprehensive tests for logger initialization and level filtering

Closes #23
Partially addresses #32
gpt-review-bot approved these changes 2026-05-02 18:02:47 +00:00
gpt-review-bot left a comment
First-time contributor

Gpt Review

Summary

The pull request comprehensively replaces all legacy log.Printf and log.Fatalf calls with structured and level-based slog logging, introduces configuration flags, and includes robust tests for logger setup. The changes are correct and idiomatic, improving both logging clarity and operational control.

Recommendation

APPROVE — Excellent work replacing unstructured logging with the standard library's slog in a systematic, robust, and idiomatic way. The addition of configuration flags for log format and level, as well as direct tests for each format and filter level, ensures maintainability and operational flexibility. No issues found—ready to merge.


Review by gpt

# Gpt Review ## Summary The pull request comprehensively replaces all legacy log.Printf and log.Fatalf calls with structured and level-based slog logging, introduces configuration flags, and includes robust tests for logger setup. The changes are correct and idiomatic, improving both logging clarity and operational control. ## Recommendation **APPROVE** — Excellent work replacing unstructured logging with the standard library's slog in a systematic, robust, and idiomatic way. The addition of configuration flags for log format and level, as well as direct tests for each format and filter level, ensures maintainability and operational flexibility. No issues found—ready to merge. --- *Review by gpt* <!-- review-bot:gpt -->
security-review-bot approved these changes 2026-05-02 18:03:18 +00:00
security-review-bot left a comment
Collaborator

Security Review

Summary

Migration to structured slog logging adds format/verbosity controls and replaces fatal exits with explicit os.Exit without introducing security risks. Inputs are validated, sensitive values (tokens/keys) are not logged, and path handling for system prompts includes robust traversal checks.

Recommendation

APPROVE — CI has passed and the changes are security-neutral or slightly improved in terms of clarity. The new logging avoids exposing secrets and continues to validate and constrain file paths correctly (including symlink resolution). No exploitable vulnerabilities were introduced. Proceed with merge.


Review by security

# Security Review ## Summary Migration to structured slog logging adds format/verbosity controls and replaces fatal exits with explicit os.Exit without introducing security risks. Inputs are validated, sensitive values (tokens/keys) are not logged, and path handling for system prompts includes robust traversal checks. ## Recommendation **APPROVE** — CI has passed and the changes are security-neutral or slightly improved in terms of clarity. The new logging avoids exposing secrets and continues to validate and constrain file paths correctly (including symlink resolution). No exploitable vulnerabilities were introduced. Proceed with merge. --- *Review by security* <!-- review-bot:security -->
sonnet-review-bot approved these changes 2026-05-02 18:03:30 +00:00
sonnet-review-bot left a comment
First-time contributor

Sonnet Review

Summary

Solid migration from log.Printf/Fatalf to Go's stdlib slog with sensible defaults, CLI flags for format and level, and good test coverage. The changes are idiomatic, maintain existing behavior (exiting on fatal errors), and improve structure and observability.

Recommendation

APPROVE — CI is green and the refactor to slog is clean and idiomatic. The new setupLogger honors format and level via flags/env, error paths now use structured logs plus os.Exit, and tests cover JSON/text formatting and level filtering. Consider minor follow-ups like routing the initial missing-flags error through slog for consistency and optionally using context.Background() in tests calling logger.Log, but these are non-blocking. Approve as is.


Review by sonnet

# Sonnet Review ## Summary Solid migration from log.Printf/Fatalf to Go's stdlib slog with sensible defaults, CLI flags for format and level, and good test coverage. The changes are idiomatic, maintain existing behavior (exiting on fatal errors), and improve structure and observability. ## Recommendation **APPROVE** — CI is green and the refactor to slog is clean and idiomatic. The new setupLogger honors format and level via flags/env, error paths now use structured logs plus os.Exit, and tests cover JSON/text formatting and level filtering. Consider minor follow-ups like routing the initial missing-flags error through slog for consistency and optionally using context.Background() in tests calling logger.Log, but these are non-blocking. Approve as is. --- *Review by sonnet* <!-- review-bot:sonnet -->
rodin merged commit cdd4f4fdf4 into main 2026-05-02 18:07:13 +00:00
rodin deleted branch feat/23-structured-logging 2026-05-02 18:07:13 +00:00
Sign in to join this conversation.
4 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: rodin/review-bot#36