feat: replace log.Printf with structured slog logging #36
Reference in New Issue
Block a user
Delete Branch "feat/23-structured-logging"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Replaces all bare
log.Printf/log.Fatalfcalls with Go stdliblog/slogstructured logging.Changes
--log-format(text/json) and--verbosity(debug/info/warn/error)log.Printf→slog.Info/slog.Debug/slog.Warnwith structured key-value attributeslog.Fatalf→slog.Error+os.Exit(1)gitea/client.gowarnings converted toslog.WarnStructured 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/slogfrom Go stdlib.Closes #23
Partially addresses #32
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
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
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