Skip to content

refactor(log): replace WithFields with format strings#736

Merged
skevetter merged 2 commits into
mainfrom
refactor/remove-withfields-logging
Apr 15, 2026
Merged

refactor(log): replace WithFields with format strings#736
skevetter merged 2 commits into
mainfrom
refactor/remove-withfields-logging

Conversation

@skevetter

@skevetter skevetter commented Apr 14, 2026

Copy link
Copy Markdown
Owner

Replace all WithFields(logrus.Fields{...}).Level() calls with Levelf() format-string equivalents across 44 files

Summary by CodeRabbit

  • Refactor
    • Standardized and simplified logging output across the application—log messages now use consistent formatted text. This is an internal change only; there are no behavior, API, or user-facing functional changes.

Replace all WithFields(logrus.Fields{...}).Level() calls with Levelf()
format-string equivalents across 44 files, removing the dependency on
logrus structured fields for application logging.
@coderabbitai

coderabbitai Bot commented Apr 14, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR replaces structured Logrus field-based logging with formatted logger calls across numerous files, removing github.com/sirupsen/logrus imports. No control-flow, API signatures, or runtime behavior changes were introduced—only log-message formatting and imports were adjusted.

Changes

Cohort / File(s) Summary
Agent workspace & CLI agent files
cmd/agent/workspace/delete.go, cmd/agent/workspace/install_dotfiles.go, cmd/agent/workspace/up.go, pkg/agent/agent.go, pkg/agent/inject.go, pkg/agent/tunnelserver/tunnelserver.go
Replaced structured WithFields(logrus.Fields{...}) logging with formatted Debugf/Infof/Errorf/Warnf calls and removed logrus imports; message content preserved but emitted as inline formatted strings.
CLI commands (cmd/...)
cmd/import.go, cmd/pro/add/cluster.go, cmd/pro/delete.go, cmd/pro/import_workspace.go, cmd/pro/login.go, cmd/pro/sleep.go, cmd/pro/start.go, cmd/pro/wakeup.go, cmd/provider/add.go, cmd/provider/delete.go, cmd/provider/set_options.go, cmd/provider/update.go, cmd/provider/use.go, cmd/stop.go
Converted completion/success/error logs from structured fields to formatted logger methods (Donef/Infof/Errorf), removing logrus usage while keeping same control flow and messages.
Client & credentials
pkg/client/clientimplementation/machine_client.go, pkg/client/clientimplementation/workspace_client.go, pkg/credentials/server.go, pkg/credentials/start.go
Switched error/debug logging to formatted messages (embedded key=value) instead of Logrus fields; request/response, refresh, and deletion logs updated accordingly.
DevContainer & driver
pkg/devcontainer/build.go, pkg/devcontainer/compose.go, pkg/devcontainer/config/prebuild.go, pkg/devcontainer/delete.go, pkg/devcontainer/feature/features.go, pkg/devcontainer/setup/lifecyclehooks.go, pkg/devcontainer/setup/setup.go, pkg/driver/docker/docker.go
Replaced structured logging with formatted logger calls across Docker, devcontainer resolution, feature handling, lifecycle hooks, and permission operations; log content preserved but emitted inline.
IDE integrations
pkg/ide/jetbrains/generic.go, pkg/ide/opener/opener.go, pkg/ide/openvscode/openvscode.go, pkg/ide/vscode/vscode.go
Converted installation, download, plugin/extension, and server discovery logs from Logrus fields to formatted Infof/Errorf/Debugf messages.
Inject / open / ssh / utilities
pkg/inject/inject.go, pkg/open/open.go, pkg/ssh/ssh_add.go, pkg/ide/..., pkg/open/...
Replaced a variety of structured debug/completion logs with formatted messages (e.g., agent download preference, opened URL, ssh-add execution) without changing behavior.
Workspace management
pkg/workspace/list.go, pkg/workspace/machine.go, pkg/workspace/pro.go, pkg/workspace/provider_update.go, pkg/workspace/workspace.go
Changed warning/completion logs to formatted Warnf/Donef/Debugf variants, removing logrus fields while retaining the same logging content and control flow.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main refactoring objective: replacing logrus WithFields structured logging with format-string equivalents across the codebase.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/remove-withfields-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 and usage tips.

@skevetter skevetter marked this pull request as ready for review April 14, 2026 23:30

@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.

Actionable comments posted: 4

🧹 Nitpick comments (1)
cmd/agent/workspace/install_dotfiles.go (1)

151-151: Include scriptPath in failure debug log for retry-loop diagnostics.

At Line 151, only the error is logged. In a multi-script loop, this loses which candidate failed.

Proposed tweak
-			logger.Debugf("script execution failed: error=%v", err)
+			logger.Debugf("script execution failed: scriptPath=%s, error=%v", installScriptPath, err)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/agent/workspace/install_dotfiles.go` at line 151, The debug log for
failed script execution omits which script failed; update the logger.Debugf call
in the retry loop (the place referencing logger and scriptPath) to include
scriptPath along with the error (e.g., logger.Debugf("script execution failed:
script=%s error=%v", scriptPath, err)) so retry-loop diagnostics can identify
the failing candidate.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/client/clientimplementation/workspace_client.go`:
- Around line 706-711: The debug log call s.log.Debugf currently passes
arguments in the wrong order which labels buf.String() as stdout and
stdout.String() as stderr; update the call in workspace_client.go
(s.log.Debugf(...) near the container status command) to pass stdout.String() as
the first %s and buf.String() as the second %s so the "stdout=%s, stderr=%s,
parsed=%v" format matches the actual variables (ensure you keep parsed as the
third argument and that both buf and stdout implement String()).

In `@pkg/credentials/server.go`:
- Line 107: The code currently logs full POST bodies via log.Debugf (e.g. the
"received docker credentials post data" call and the similar Debugf calls at the
other occurrences), which may contain secrets; replace those raw-payload debug
logs with either (a) a sanitized log that redacts sensitive fields by parsing
the payload and removing keys like "password", "token", "signature", "auth",
"secret", or (b) a safe summary (e.g. payload size, JSON keys present, or a
hash) instead of the full body. Update each log.Debugf occurrence (the call that
prints string(out) and the similar calls at the other locations) to emit only
redacted/summarized information and ensure any structured logging uses
non-sensitive keys.

In `@pkg/devcontainer/feature/features.go`:
- Around line 44-45: The warning builds a raw string so the
`${escapeQuotesForShell(feature.id)}` placeholder is not interpolated; update
the construction of warningHeader (the variable containing the deprecated
message) to concatenate or format in the actual escaped feature id returned by
escapeQuotesForShell(feature.id) (e.g., use string concatenation or fmt.Sprintf)
instead of leaving the placeholder inside a raw back-quoted string literal so
the real feature id is injected into the message.

In `@pkg/devcontainer/setup/lifecyclehooks.go`:
- Around line 208-213: The log and error message currently hard-code
"postCreateCommand"; update them to use the current lifecycle hook variable
(e.g., hookName or similar used in this function) instead so failures reflect
the actual hook. Replace the "postCreateCommand" literal in the log.Debugf call
and in the returned fmt.Errorf with the hook variable, keeping cmd.Args and err
in the debug log and preserving the command string built from c in the error
return (format still: failed to run: <joined command>, error: %w) so the
messages show the correct hook name, command, and error.

---

Nitpick comments:
In `@cmd/agent/workspace/install_dotfiles.go`:
- Line 151: The debug log for failed script execution omits which script failed;
update the logger.Debugf call in the retry loop (the place referencing logger
and scriptPath) to include scriptPath along with the error (e.g.,
logger.Debugf("script execution failed: script=%s error=%v", scriptPath, err))
so retry-loop diagnostics can identify the failing candidate.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6c42ff5c-e92b-47a9-871a-7cd3dcd3cf5a

📥 Commits

Reviewing files that changed from the base of the PR and between f28dcb1 and f2e6c51.

📒 Files selected for processing (44)
  • cmd/agent/workspace/delete.go
  • cmd/agent/workspace/install_dotfiles.go
  • cmd/agent/workspace/up.go
  • cmd/import.go
  • cmd/pro/add/cluster.go
  • cmd/pro/delete.go
  • cmd/pro/import_workspace.go
  • cmd/pro/login.go
  • cmd/pro/sleep.go
  • cmd/pro/start.go
  • cmd/pro/wakeup.go
  • cmd/provider/add.go
  • cmd/provider/delete.go
  • cmd/provider/set_options.go
  • cmd/provider/update.go
  • cmd/provider/use.go
  • cmd/stop.go
  • pkg/agent/agent.go
  • pkg/agent/inject.go
  • pkg/agent/tunnelserver/tunnelserver.go
  • pkg/client/clientimplementation/machine_client.go
  • pkg/client/clientimplementation/workspace_client.go
  • pkg/credentials/server.go
  • pkg/credentials/start.go
  • pkg/devcontainer/build.go
  • pkg/devcontainer/compose.go
  • pkg/devcontainer/config/prebuild.go
  • pkg/devcontainer/delete.go
  • pkg/devcontainer/feature/features.go
  • pkg/devcontainer/setup/lifecyclehooks.go
  • pkg/devcontainer/setup/setup.go
  • pkg/driver/docker/docker.go
  • pkg/ide/jetbrains/generic.go
  • pkg/ide/opener/opener.go
  • pkg/ide/openvscode/openvscode.go
  • pkg/ide/vscode/vscode.go
  • pkg/inject/inject.go
  • pkg/open/open.go
  • pkg/ssh/ssh_add.go
  • pkg/workspace/list.go
  • pkg/workspace/machine.go
  • pkg/workspace/pro.go
  • pkg/workspace/provider_update.go
  • pkg/workspace/workspace.go

Comment thread pkg/client/clientimplementation/workspace_client.go
Comment thread pkg/credentials/server.go Outdated
Comment on lines +44 to +45
warningHeader += `(!) WARNING: Using the deprecated Feature ` +
`"${escapeQuotesForShell(feature.id)}". This Feature will no longer receive any further updates/support.\n`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Deprecated-feature warning now prints a literal placeholder instead of the feature id

Line 45 is inside a raw string literal, so ${escapeQuotesForShell(feature.id)} is not evaluated and will be shown literally in the generated script.

🔧 Proposed fix
 	if feature.Deprecated {
-		warningHeader += `(!) WARNING: Using the deprecated Feature ` +
-			`"${escapeQuotesForShell(feature.id)}". This Feature will no longer receive any further updates/support.\n`
+		warningHeader += `(!) WARNING: Using the deprecated Feature "` +
+			id +
+			`". This Feature will no longer receive any further updates/support.\n`
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/devcontainer/feature/features.go` around lines 44 - 45, The warning
builds a raw string so the `${escapeQuotesForShell(feature.id)}` placeholder is
not interpolated; update the construction of warningHeader (the variable
containing the deprecated message) to concatenate or format in the actual
escaped feature id returned by escapeQuotesForShell(feature.id) (e.g., use
string concatenation or fmt.Sprintf) instead of leaving the placeholder inside a
raw back-quoted string literal so the real feature id is injected into the
message.

Comment on lines +208 to 213
log.Debugf(
"failed running postCreateCommand lifecycle script: command=%v, error=%v",
cmd.Args,
err,
)
return fmt.Errorf("failed to run: %s, error: %w", strings.Join(c, " "), err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Use the current hook name in failure logs instead of a hard-coded one.

At Line 209, the message always says postCreateCommand, which is misleading when this path runs for other lifecycle hooks.

Suggested fix
-				log.Debugf(
-					"failed running postCreateCommand lifecycle script: command=%v, error=%v",
-					cmd.Args,
-					err,
-				)
+				log.Debugf(
+					"failed running %s lifecycle script: command=%v, error=%v",
+					name,
+					cmd.Args,
+					err,
+				)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
log.Debugf(
"failed running postCreateCommand lifecycle script: command=%v, error=%v",
cmd.Args,
err,
)
return fmt.Errorf("failed to run: %s, error: %w", strings.Join(c, " "), err)
log.Debugf(
"failed running %s lifecycle script: command=%v, error=%v",
name,
cmd.Args,
err,
)
return fmt.Errorf("failed to run: %s, error: %w", strings.Join(c, " "), err)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/devcontainer/setup/lifecyclehooks.go` around lines 208 - 213, The log and
error message currently hard-code "postCreateCommand"; update them to use the
current lifecycle hook variable (e.g., hookName or similar used in this
function) instead so failures reflect the actual hook. Replace the
"postCreateCommand" literal in the log.Debugf call and in the returned
fmt.Errorf with the hook variable, keeping cmd.Args and err in the debug log and
preserving the command string built from c in the error return (format still:
failed to run: <joined command>, error: %w) so the messages show the correct
hook name, command, and error.

- Fix stdout/stderr argument swap in workspace_client.go debug log
- Stop logging raw credential payloads in server.go, log byte length instead
- Use dynamic hook name instead of hardcoded "postCreateCommand" in lifecyclehooks.go
@skevetter

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 15, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@skevetter skevetter merged commit f0b243e into main Apr 15, 2026
41 checks passed
@skevetter skevetter deleted the refactor/remove-withfields-logging branch April 15, 2026 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant