From ca8d796630a0e29066942d1e74eb27b4c47bd986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Thu, 6 Jul 2023 17:02:12 +0200 Subject: [PATCH] Improve log messages (#4045) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer Co-authored-by: André Duffeck --- changelog/unreleased/improve-log-messages.md | 5 +++++ internal/grpc/interceptors/log/log.go | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/improve-log-messages.md diff --git a/changelog/unreleased/improve-log-messages.md b/changelog/unreleased/improve-log-messages.md new file mode 100644 index 0000000000..611260b3a2 --- /dev/null +++ b/changelog/unreleased/improve-log-messages.md @@ -0,0 +1,5 @@ +Enhancement: Log error message in grpc interceptor + +The grpc log interceptor now logs the actual error message + +https://github.com/cs3org/reva/pull/4045 diff --git a/internal/grpc/interceptors/log/log.go b/internal/grpc/interceptors/log/log.go index 0da26c81cd..6335e471f2 100644 --- a/internal/grpc/interceptors/log/log.go +++ b/internal/grpc/interceptors/log/log.go @@ -51,10 +51,13 @@ func NewUnary() grpc.UnaryServerInterceptor { log := appctx.GetLogger(ctx) var event *zerolog.Event + var msg string if code != codes.OK { event = log.Error() + msg = err.Error() } else { event = log.Debug() + msg = "unary" } event.Str("user-agent", userAgent). @@ -63,7 +66,7 @@ func NewUnary() grpc.UnaryServerInterceptor { Str("start", start.Format("02/Jan/2006:15:04:05 -0700")). Str("end", end.Format("02/Jan/2006:15:04:05 -0700")).Int("time_ns", int(diff)). Str("code", code.String()). - Msg("unary") + Msg(msg) return res, err } @@ -91,10 +94,13 @@ func NewStream() grpc.StreamServerInterceptor { log := appctx.GetLogger(ss.Context()) var event *zerolog.Event + var msg string if code != codes.OK { event = log.Error() + msg = err.Error() } else { - event = log.Info() + event = log.Debug() + msg = "stream" } event.Str("user-agent", userAgent). @@ -103,7 +109,7 @@ func NewStream() grpc.StreamServerInterceptor { Str("start", start.Format("02/Jan/2006:15:04:05 -0700")). Str("end", end.Format("02/Jan/2006:15:04:05 -0700")).Int("time_ns", int(diff)). Str("code", code.String()). - Msg("stream") + Msg(msg) return err }