Skip to content

Commit

Permalink
feat(cloudrequestlog): migrate CodeToLevel to slog
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The API now returns a slog.Level instead of
zapcore.Level.
  • Loading branch information
odsod committed Oct 21, 2024
1 parent 54b509a commit d834237
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 30 deletions.
30 changes: 1 addition & 29 deletions cloudrequestlog/codetolevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,11 @@ package cloudrequestlog
import (
"log/slog"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"google.golang.org/grpc/codes"
)

// CodeToLevel returns the default [zapcore.Level] for requests with the provided [codes.Code].
// Deprecated: Zap has been replaced by slog.
func CodeToLevel(code codes.Code) zapcore.Level {
switch code {
case codes.OK:
return zap.InfoLevel
case
codes.NotFound,
codes.InvalidArgument,
codes.AlreadyExists,
codes.FailedPrecondition,
codes.Unauthenticated,
codes.PermissionDenied,
codes.DeadlineExceeded,
codes.OutOfRange,
codes.Canceled,
codes.Aborted,
codes.Unavailable,
codes.ResourceExhausted,
codes.Unimplemented:
return zap.WarnLevel
default:
return zap.ErrorLevel
}
}

// CodeToLevel returns the default [slog.Level] for requests with the provided [codes.Code].
func codeToLevel(code codes.Code) slog.Level {
func CodeToLevel(code codes.Code) slog.Level {
switch code {
case codes.OK:
return slog.LevelInfo
Expand Down
2 changes: 1 addition & 1 deletion cloudrequestlog/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (l *Middleware) codeToLevel(code codes.Code) slog.Level {
if level, ok := l.Config.CodeToLevel[code]; ok {
return level
}
return codeToLevel(code)
return CodeToLevel(code)
}

func (l *Middleware) statusToLevel(status int) slog.Level {
Expand Down

0 comments on commit d834237

Please sign in to comment.