Skip to content

Commit

Permalink
feat(cloudrequestlog): use slog.Level for config values
Browse files Browse the repository at this point in the history
The string values are equivalent (debug/info/warn/error) across zap and
slog, so although this is technically a breaking change, the risk of
breakage is small, and the migration if it happens is simple.
  • Loading branch information
odsod committed Oct 7, 2024
1 parent c26c347 commit 7890d89
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions cloudrequestlog/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package cloudrequestlog

import (
"go.uber.org/zap/zapcore"
"log/slog"

"google.golang.org/grpc/codes"
)

Expand All @@ -12,7 +13,7 @@ type Config struct {
// Default value, 0, means that no messages will be truncated.
MessageSizeLimit int `onGCE:"1024"`
// CodeToLevel enables overriding the default gRPC code to level conversion.
CodeToLevel map[codes.Code]zapcore.Level
CodeToLevel map[codes.Code]slog.Level
// StatusToLevel enables overriding the default HTTP status code to level conversion.
StatusToLevel map[int]zapcore.Level
StatusToLevel map[int]slog.Level
}
4 changes: 2 additions & 2 deletions cloudrequestlog/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ func (l *Middleware) applyMessageTransform(message proto.Message) proto.Message

func (l *Middleware) codeToLevel(code codes.Code) zapcore.Level {
if level, ok := l.Config.CodeToLevel[code]; ok {
return level
return slogToLevel(level)
}
return CodeToLevel(code)
}

func (l *Middleware) statusToLevel(status int) zapcore.Level {
if level, ok := l.Config.StatusToLevel[status]; ok {
return level
return slogToLevel(level)
}
switch {
case status < http.StatusBadRequest:
Expand Down

0 comments on commit 7890d89

Please sign in to comment.