Skip to content

refactor: replace logrus with log/slog and tint#88

Merged
twangodev merged 2 commits into
mainfrom
refactor/slog-logging
Jun 29, 2026
Merged

refactor: replace logrus with log/slog and tint#88
twangodev merged 2 commits into
mainfrom
refactor/slog-logging

Conversation

@twangodev

@twangodev twangodev commented Jun 29, 2026

Copy link
Copy Markdown
Owner

Replaces the deprecated logrus logger with the standard-library log/slog plus the tint handler for colored output. Logs now write to stderr (was stdout) and color auto-disables when output is piped.

Summary by CodeRabbit

  • Chores
    • Switched application logging to a newer structured logging setup with clearer, more consistent output.
    • Improved console log formatting and error presentation in terminal environments.
    • Updated dependency requirements to match the new logging approach.

Swap the deprecated logrus logger for the standard-library log/slog with the lmittmann/tint handler for colored, human-readable output.

- Logs now write to stderr (was stdout), per CLI convention
- Color auto-disables when output is not a TTY
- logrus Trace/Debug both map to slog.Debug; --debug raises the threshold
- log.Fatal becomes slog.Error + os.Exit(1)
Copilot AI review requested due to automatic review settings June 29, 2026 02:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@twangodev, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 41 minutes and 27 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 36ceca1c-cffa-4fda-ad76-2d248995d067

📥 Commits

Reviewing files that changed from the base of the PR and between f4d0a78 and fc6c6e7.

📒 Files selected for processing (2)
  • cycler.go
  • rpc.go
📝 Walkthrough

Walkthrough

Replaces logrus with Go's standard log/slog and tint across main.go, rpc.go, and cycler.go. Logger initialization moves to a tint handler with terminal detection; a logLevel var controls debug/info level. All structured log calls are rewritten to slog equivalents. go.mod adds tint, promotes isatty to direct, and removes logrus.

logrus → slog/tint migration

Layer / File(s) Summary
Dependency updates
go.mod
Adds github.com/lmittmann/tint v1.1.3, promotes go-isatty to direct, removes logrus, adds testify as indirect, moves golang.org/x/net to indirect.
Logger init and exec() migration
main.go
Adds logLevel (slog.LevelVar), initializes default slog logger with tint handler and colorable/isatty terminal detection, migrates all log calls in exec() and main loop, updates fatal path to slog.Error + os.Exit(1).
rpc.go login/logout migration
rpc.go
Replaces log.Entry-based helpers with *slog.Logger; getRPCLogCtx returns slog.With("loggedIn", ...), and logout errors use tint.Err(err).
cycler.go cycle() migration
cycler.go
Swaps all logrus calls to slog in cycle(), including replacing WithFields(...).Infoln(...) with slog.Info(...) carrying a scrobbling attribute.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop hop, logrus is gone,
slog and tint carry on!
Structured fields, colors bright,
terminal-aware and light.
The rabbit logs with delight! 🌈

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: migrating logging from logrus to log/slog with tint formatting.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/slog-logging

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@socket-security

socket-security Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedgithub.com/​lmittmann/​tint@​v1.1.3100100100100100

View full report

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
cycler.go (1)

27-27: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Preserve the RPC errors in these retry/fallback logs. These branches only emit generic failure messages, so the reconnect loop loses the reason Discord rejected the payload or dropped the connection. Attach err/err1/err2 to the log records, including both 59-73 paths.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cycler.go` at line 27, The retry/fallback logging in the cycler flow is
dropping the underlying RPC failure details, so update the affected slog.Warn
branches to include the relevant error values. In the reconnect/activity
handling paths in cycler.go, preserve the reason Discord rejected the payload or
disconnected by attaching err, err1, and err2 to the log records in both the
59-73 branches and the generic reconnect fallback message. Use the existing
logging points around the activity keep/reconnect logic so the error context is
emitted with each warning.
rpc.go (1)

23-25: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Keep the login error on the warning path.

rpcClient.Login() failures should include the returned error here too, so auth/transport problems aren’t reduced to a generic warning.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rpc.go` around lines 23 - 25, The login failure handling in rpcClient.Login()
is dropping the returned error and only emitting a generic warning. Update the
warning path in the login flow to include the err from rpcClient.Login()
alongside the existing context/logout behavior, using the same login branch so
auth or transport failures are preserved in the warning output.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cycler.go`:
- Line 27: The retry/fallback logging in the cycler flow is dropping the
underlying RPC failure details, so update the affected slog.Warn branches to
include the relevant error values. In the reconnect/activity handling paths in
cycler.go, preserve the reason Discord rejected the payload or disconnected by
attaching err, err1, and err2 to the log records in both the 59-73 branches and
the generic reconnect fallback message. Use the existing logging points around
the activity keep/reconnect logic so the error context is emitted with each
warning.

In `@rpc.go`:
- Around line 23-25: The login failure handling in rpcClient.Login() is dropping
the returned error and only emitting a generic warning. Update the warning path
in the login flow to include the err from rpcClient.Login() alongside the
existing context/logout behavior, using the same login branch so auth or
transport failures are preserved in the warning output.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e96c81a3-c756-4426-b90c-c430750937e5

📥 Commits

Reviewing files that changed from the base of the PR and between 7dc4588 and f4d0a78.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (4)
  • cycler.go
  • go.mod
  • main.go
  • rpc.go

Attach the dropped error values (err/err1/err2) to the keep-activity, RPC retry, reconnect, and login-failure log records so the reason Discord rejected the payload or disconnected is preserved.
@twangodev twangodev merged commit ca655f0 into main Jun 29, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants