Skip to content

refactor(logging): replace logrus with stdlib slog and add path helpers#159

Merged
AnnatarHe merged 2 commits intomainfrom
refactor/replace-logrus-with-slog-and-fix-typos
Dec 25, 2025
Merged

refactor(logging): replace logrus with stdlib slog and add path helpers#159
AnnatarHe merged 2 commits intomainfrom
refactor/replace-logrus-with-slog-and-fix-typos

Conversation

@AnnatarHe
Copy link
Copy Markdown
Contributor

Summary

  • Replace github.com/sirupsen/logrus with Go stdlib log/slog across all packages
  • Add model/path.go with centralized path helper functions for config/storage paths
  • Fix typo: SocketTopicProccessorSocketTopicProcessor

Test plan

  • Build succeeds (go build ./...)
  • Daemon tests pass (go test ./daemon/...)
  • Model tests pass (go test ./model/...)
  • Manual testing of CLI commands

🤖 Generated with Claude Code

- Replace github.com/sirupsen/logrus with log/slog across all packages
- Add model/path.go with centralized path helper functions
- Fix typo: SocketTopicProccessor -> SocketTopicProcessor
- Remove logrus dependency from go.mod

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @AnnatarHe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the application's logging infrastructure by migrating from a third-party library to the native Go slog package. This change aims to streamline logging, potentially improve performance, and reduce the project's dependency footprint. Additionally, it introduces a new module to centralize path management, enhancing code organization and making path-related operations more robust. A minor but important typo in a daemon function name has also been corrected.

Highlights

  • Logging Refactor: Replaced the external github.com/sirupsen/logrus logging library with Go's standard library log/slog across the entire codebase, standardizing logging practices and reducing external dependencies.
  • Centralized Path Helpers: Introduced a new file model/path.go which centralizes helper functions for managing configuration and storage paths, improving consistency and maintainability.
  • Typo Correction: Fixed a minor typo in the SocketTopicProcessor function name within the daemon package, correcting Proccessor to Processor.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 25, 2025

Codecov Report

❌ Patch coverage is 10.41667% with 172 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
model/path.go 0.00% 29 Missing ⚠️
model/dotfile_apps.go 16.66% 15 Missing ⚠️
commands/dotfiles_pull.go 0.00% 14 Missing ⚠️
commands/gc.go 0.00% 14 Missing ⚠️
model/db.go 0.00% 14 Missing ⚠️
model/command.go 0.00% 13 Missing ⚠️
commands/track.go 25.00% 12 Missing ⚠️
commands/logger.go 0.00% 11 Missing ⚠️
commands/alias.go 0.00% 10 Missing ⚠️
commands/dotfiles_push.go 0.00% 8 Missing ⚠️
... and 12 more
Flag Coverage Δ
unittests 20.41% <10.41%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
daemon/handlers.go 75.00% <100.00%> (ø)
model/api.go 100.00% <100.00%> (ø)
model/exclude.go 100.00% <100.00%> (ø)
cmd/cli/main.go 0.00% <0.00%> (ø)
cmd/daemon/main.go 0.00% <0.00%> (ø)
commands/auth.go 0.00% <0.00%> (ø)
commands/ls.go 0.00% <0.00%> (ø)
commands/query.go 86.00% <50.00%> (ø)
commands/sync.go 0.00% <0.00%> (ø)
commands/utils.go 0.00% <0.00%> (ø)
... and 15 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a great step forward in modernizing the codebase by replacing logrus with the standard library's slog for structured logging. The changes are applied consistently across the project. The introduction of model/path.go to centralize path management is also a very good initiative. I've provided some feedback to improve the portability of the new path helpers and to refine some of the new logging statements. Overall, this is a solid refactoring effort.

Comment thread model/path.go
Comment on lines +1 to +74
package model

import (
"fmt"
"os"
"path/filepath"
)

// GetBaseStoragePath returns the base storage path for shelltime
// e.g., /Users/username/.shelltime
func GetBaseStoragePath() string {
return os.ExpandEnv("$HOME/" + COMMAND_BASE_STORAGE_FOLDER)
}

// GetStoragePath returns the full path for a given subpath within the storage folder
// e.g., GetStoragePath("config.toml") returns /Users/username/.shelltime/config.toml
func GetStoragePath(subpath string) string {
return filepath.Join(GetBaseStoragePath(), subpath)
}

// GetConfigFilePath returns the path to the main config file
func GetConfigFilePath() string {
return GetStoragePath("config.toml")
}

// GetLocalConfigFilePath returns the path to the local config file
func GetLocalConfigFilePath() string {
return GetStoragePath("config.local.toml")
}

// GetLogFilePath returns the path to the log file
func GetLogFilePath() string {
return GetStoragePath("log.log")
}

// GetCommandsStoragePath returns the path to the commands storage folder
func GetCommandsStoragePath() string {
return os.ExpandEnv("$HOME/" + COMMAND_STORAGE_FOLDER)
}

// GetPreCommandFilePath returns the path to the pre-command storage file
func GetPreCommandFilePath() string {
return os.ExpandEnv("$HOME/" + COMMAND_PRE_STORAGE_FILE)
}

// GetPostCommandFilePath returns the path to the post-command storage file
func GetPostCommandFilePath() string {
return os.ExpandEnv("$HOME/" + COMMAND_POST_STORAGE_FILE)
}

// GetCursorFilePath returns the path to the cursor storage file
func GetCursorFilePath() string {
return os.ExpandEnv("$HOME/" + COMMAND_CURSOR_STORAGE_FILE)
}

// GetHeartbeatLogFilePath returns the path to the heartbeat log file
func GetHeartbeatLogFilePath() string {
return os.ExpandEnv("$HOME/" + HEARTBEAT_LOG_FILE)
}

// GetSyncPendingFilePath returns the path to the sync pending file
func GetSyncPendingFilePath() string {
return os.ExpandEnv("$HOME/" + SYNC_PENDING_FILE)
}

// GetBinFolderPath returns the path to the bin folder
func GetBinFolderPath() string {
return os.ExpandEnv(fmt.Sprintf("$HOME/%s/bin", COMMAND_BASE_STORAGE_FOLDER))
}

// GetHooksFolderPath returns the path to the hooks folder
func GetHooksFolderPath() string {
return os.ExpandEnv(fmt.Sprintf("$HOME/%s/hooks", COMMAND_BASE_STORAGE_FOLDER))
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The new path helper functions are a great idea for centralizing path logic. However, many of them use os.ExpandEnv with hardcoded / separators (e.g., os.ExpandEnv("$HOME/" + ...)), which is not portable and will cause issues on Windows.

I suggest rewriting this file to use path/filepath.Join for all path constructions. This will make the path helpers robust and platform-independent. The proposed implementation below also makes GetStoragePath variadic for more flexibility.

package model

import (
	"os"
	"path/filepath"
)

// GetBaseStoragePath returns the base storage path for shelltime
// e.g., /Users/username/.shelltime
func GetBaseStoragePath() string {
	home, err := os.UserHomeDir()
	if err != nil {
		// Fallback for environments where home dir is not available.
		return filepath.Join(os.TempDir(), COMMAND_BASE_STORAGE_FOLDER)
	}
	return filepath.Join(home, COMMAND_BASE_STORAGE_FOLDER)
}

// GetStoragePath returns the full path for a given subpath within the storage folder
// e.g., GetStoragePath("config.toml") returns /Users/username/.shelltime/config.toml
func GetStoragePath(subpaths ...string) string {
	return filepath.Join(append([]string{GetBaseStoragePath()}, subpaths...)...)
}

// GetConfigFilePath returns the path to the main config file
func GetConfigFilePath() string {
	return GetStoragePath("config.toml")
}

// GetLocalConfigFilePath returns the path to the local config file
func GetLocalConfigFilePath() string {
	return GetStoragePath("config.local.toml")
}

// GetLogFilePath returns the path to the log file
func GetLogFilePath() string {
	return GetStoragePath("log.log")
}

// GetCommandsStoragePath returns the path to the commands storage folder
func GetCommandsStoragePath() string {
	return GetStoragePath("commands")
}

// GetPreCommandFilePath returns the path to the pre-command storage file
func GetPreCommandFilePath() string {
	return GetStoragePath("commands", "pre.txt")
}

// GetPostCommandFilePath returns the path to the post-command storage file
func GetPostCommandFilePath() string {
	return GetStoragePath("commands", "post.txt")
}

// GetCursorFilePath returns the path to the cursor storage file
func GetCursorFilePath() string {
	return GetStoragePath("commands", "cursor.txt")
}

// GetHeartbeatLogFilePath returns the path to the heartbeat log file
func GetHeartbeatLogFilePath() string {
	return GetStoragePath("coding-heartbeat.data.log")
}

// GetSyncPendingFilePath returns the path to the sync pending file
func GetSyncPendingFilePath() string {
	return GetStoragePath("sync-pending.jsonl")
}

// GetBinFolderPath returns the path to the bin folder
func GetBinFolderPath() string {
	return GetStoragePath("bin")
}

// GetHooksFolderPath returns the path to the hooks folder
func GetHooksFolderPath() string {
	return GetStoragePath("hooks")
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are absolutely right. Please use path.join to compose the path instead of hard-coded /. @claude

Copy link
Copy Markdown
Contributor

@claude claude Bot Dec 25, 2025

Choose a reason for hiding this comment

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

Claude finished @AnnatarHe's task in 2m 54s —— View job


Path portability fix completed

I've updated model/path.go to use filepath.Join for cross-platform compatibility, following the excellent suggestion from @gemini-code-assist.

Changes made:

  • ✅ Replaced os.ExpandEnv("$HOME/...") with os.UserHomeDir() + filepath.Join
  • ✅ Added fallback to os.TempDir() when home directory is unavailable
  • ✅ Made GetStoragePath() variadic for flexible path construction
  • ✅ All path helpers now use filepath.Join for Windows compatibility
  • ✅ Removed hardcoded / separators throughout the file

The implementation now properly handles paths across all platforms (Linux, macOS, Windows) by using the standard library's platform-aware path joining functions.

Commit: b6e8bf6


|

Comment thread commands/logger.go
err := os.MkdirAll(baseFolder, 0755)
if err != nil {
slog.Error("[ShellTime.xyz] failed to create log directory: ", slog.Any("err", err))
slog.Error("[ShellTime.xyz] failed to create log directory", slog.Any("err", err))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For structured logging, it's better to move contextual information from the message string into key-value pairs. This makes logs easier to parse, filter, and query. The [ShellTime.xyz] prefix should be a field, for example component. This applies to the other similar error logs in this function as well.

Suggested change
slog.Error("[ShellTime.xyz] failed to create log directory", slog.Any("err", err))
slog.Error("failed to create log directory", slog.String("component", "ShellTime.xyz"), slog.Any("err", err))

Comment thread daemon/handlers.go
func SocketTopicProcessor(messages <-chan *message.Message) {
for msg := range messages {
ctx := context.Background()
slog.InfoContext(ctx, "received message: ", slog.String("msg.uuid", msg.UUID))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The log message has a trailing space. It's a minor issue, but for consistency and cleaner logs, it's best to remove it.

Suggested change
slog.InfoContext(ctx, "received message: ", slog.String("msg.uuid", msg.UUID))
slog.InfoContext(ctx, "received message", slog.String("msg.uuid", msg.UUID))

Replace hardcoded '/' separators and os.ExpandEnv("$HOME/...") with
filepath.Join and os.UserHomeDir() for Windows compatibility.
- Use os.UserHomeDir() instead of $HOME env var
- Add fallback to os.TempDir() when home dir unavailable
- Make GetStoragePath variadic for flexible path construction
- All path helpers now use filepath.Join for portability

Co-authored-by: Le He <AnnatarHe@users.noreply.github.com>
@AnnatarHe AnnatarHe merged commit 03f7962 into main Dec 25, 2025
2 of 3 checks passed
@AnnatarHe AnnatarHe deleted the refactor/replace-logrus-with-slog-and-fix-typos branch December 25, 2025 13:37
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.

1 participant