From 7890d89359c5bee6fb688d246217790e914bc7cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20S=C3=B6derlund?= Date: Mon, 7 Oct 2024 13:20:36 +0200 Subject: [PATCH] feat(cloudrequestlog): use slog.Level for config values 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. --- cloudrequestlog/config.go | 7 ++++--- cloudrequestlog/middleware.go | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cloudrequestlog/config.go b/cloudrequestlog/config.go index cc38c41f..cbbf1cd3 100644 --- a/cloudrequestlog/config.go +++ b/cloudrequestlog/config.go @@ -1,7 +1,8 @@ package cloudrequestlog import ( - "go.uber.org/zap/zapcore" + "log/slog" + "google.golang.org/grpc/codes" ) @@ -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 } diff --git a/cloudrequestlog/middleware.go b/cloudrequestlog/middleware.go index a1dbf4ef..623661ac 100644 --- a/cloudrequestlog/middleware.go +++ b/cloudrequestlog/middleware.go @@ -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: