Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: replace logrus with slog#781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JoannaaKL merged 4 commits intogithub:mainfromricochet:fix/logrus-to-slog
Aug 12, 2025

Conversation

ricochet
Copy link
Contributor

Thegolang's blog article introducing slog calls out logrus directly as tooling it aims to replace with a solution in the standard language library.

This change replaces logrus with slog and adjusts some of the log outputs to use structured logs.

Closes:#780

ivanstepanovftw and JoannaaKL reacted with heart emoji
@CopilotCopilotAI review requested due to automatic review settingsJuly 29, 2025 00:06
@ricochetricochet requested a review froma team as acode ownerJuly 29, 2025 00:06
Copilot

This comment was marked as outdated.

Copy link
Contributor

@CopilotCopilotAI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR replaces the logrus logging library with Go's standard library slog for structured logging. The change modernizes the logging approach by adopting the recommended standard library solution that aims to replace third-party logging libraries like logrus.

  • Replace logrus imports with standard library slog across the codebase
  • Convert logging calls to use structured logging with key-value pairs
  • Update logger initialization and configuration to use slog handlers

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

FileDescription
go.modRemove logrus dependency from module requirements
pkg/log/io.goUpdate IOLogger to use slog.Logger and convert log messages to structured format
pkg/log/io_test.goUpdate test setup to use slog with custom time removal function
internal/ghmcp/server.goReplace logrus with slog in server initialization and logging calls

stdLogger:=log.New(logrusLogger.Writer(),"stdioserver",0)
logger:=slog.New(slogHandler)
logger.Info("starting server","version",cfg.Version,"host",cfg.Host,"dynamicToolsets",cfg.DynamicToolsets,"readOnly",cfg.ReadOnly)
stdLogger:=log.New(os.Stderr,stdioServerLogPrefix,0)
Copy link
Preview

CopilotAIJul 30, 2025

Choose a reason for hiding this comment

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

The stdLogger is created with os.Stderr as output, but when a log file is configured, the slog logger uses the file while stdLogger still writes to stderr. This creates inconsistent logging destinations. Consider using the same output destination for both loggers.

Note: See the diff below for a potential fix:

@@ -206,18 +206,21 @@ stdioServer := server.NewStdioServer(ghServer)  var slogHandler slog.Handler+var logOutput io.Writer if cfg.LogFilePath != "" { file, err := os.OpenFile(cfg.LogFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600) if err != nil { return fmt.Errorf("failed to open log file: %w", err) }+logOutput = file slogHandler = slog.NewTextHandler(file, &slog.HandlerOptions{Level: slog.LevelDebug}) } else {+logOutput = os.Stderr slogHandler = slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelInfo}) } logger := slog.New(slogHandler) logger.Info("starting server", "version", cfg.Version, "host", cfg.Host, "dynamicToolsets", cfg.DynamicToolsets, "readOnly", cfg.ReadOnly)-stdLogger := log.New(os.Stderr, stdioServerLogPrefix, 0)+stdLogger := log.New(logOutput, stdioServerLogPrefix, 0) stdioServer.SetErrorLogger(stdLogger)  if cfg.ExportTranslations {

Copilot uses AI. Check for mistakes.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Please double-check the io.Writer to stdLogger as file logOutput is desired. I updated the commit to follow the GH recommendation

@mattdholloway
Copy link
Contributor

mattdholloway commentedJul 30, 2025
edited
Loading

@ricochet Could you runscript/licenses to update the licenses on this branch? Otherwise I'm a fan of this change, and reducing our dependencies.

ricochet and ivanstepanovftw reacted with thumbs up emoji

- Adjust some logs to use structured outputs- Set stdioserver log prefix as const- Do not export test func removeTimeAttrSigned-off-by: Bailey Hayes <behayes2@gmail.com>
Copy link
Contributor

@mattdhollowaymattdholloway left a comment

Choose a reason for hiding this comment

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

Looks good!

@JoannaaKLJoannaaKL merged commit3479d02 intogithub:mainAug 12, 2025
10 checks passed
nickytonline pushed a commit to nickytonline/github-mcp-http that referenced this pull requestOct 4, 2025
- Adjust some logs to use structured outputs- Set stdioserver log prefix as const- Do not export test func removeTimeAttrSigned-off-by: Bailey Hayes <behayes2@gmail.com>Co-authored-by: Matt Holloway <mattdholloway@github.com>Co-authored-by: JoannaaKL <joannaakl@github.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

Copilot code reviewCopilotCopilot left review comments

@mattdhollowaymattdhollowaymattdholloway approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Use slog for logging instead of logrus
3 participants
@ricochet@mattdholloway@JoannaaKL

[8]ページ先頭

©2009-2025 Movatter.jp