Skip to content

simplify Level type and align with slog.Level - #818

Merged
johanbrandhorst merged 2 commits into
grpc-ecosystem:mainfrom
rashmi-tondare:main
Mar 24, 2026
Merged

simplify Level type and align with slog.Level#818
johanbrandhorst merged 2 commits into
grpc-ecosystem:mainfrom
rashmi-tondare:main

Conversation

@rashmi-tondare

Copy link
Copy Markdown
Contributor

This PR addresses issue #738

Changes

  • Type alias refactoring: Changed Level type from a custom independent type to an alias of slog.Level in interceptors/logging/slog.go
  • Simplified documentation: Updated comments in slog.go to reflect that Level is now an alias, removing the inherited documentation about level numbering constraints (which now belong to slog)

Benefits

  • Better alignment with Go's standard library
  • Reduced code duplication
  • Seamless interoperability between go-grpc-middleware logging and standard slog
  • Non-breaking change for users of the library

Verification

  • Confirmed the Level alias maintains the same API surface as the previous implementation
  • All existing constants (LevelDebug, LevelInfo, LevelWarn, LevelError) continue to work identically
  • No changes required to the Logger interface or existing middleware implementations
  • Verified by checking usage in LoggerFunc, DefaultClientCodeToLevel, and internal test code — all continue to work as expected

@rashmi-tondare

rashmi-tondare commented Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

The linting workflow fails because it's unable to access the Medium link in the readme (see logs here). The link is accessible but looks like Medium blocks this automated check.

Is there a way to fix or skip this check?

@johanbrandhorst johanbrandhorst left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One question, this looks great.

"context"

"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors"
_ "log/slog"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we need this?

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.

The only purpose of adding this was so that the documentation comment for the Logger interface renders the hyperlink to the slog.Level implementation.
It is non-essential and I can remove it if not required.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Huh, TIL

@johanbrandhorst

Copy link
Copy Markdown
Collaborator

The linting workflow fails because it's unable to access the Medium link in the readme (see logs here). The link is accessible but looks like Medium blocks this automated check.

Is there a way to fix or skip this check?

Sorry about that, we can just ignore that failure.

@johanbrandhorst
johanbrandhorst merged commit 9150cbd into grpc-ecosystem:main Mar 24, 2026
4 of 5 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