Skip to content

Commit

Permalink
Improve log messages (#4045)
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
Co-authored-by: André Duffeck <[email protected]>
  • Loading branch information
butonic and aduffeck authored Jul 6, 2023
1 parent 5009aa4 commit ca8d796
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/improve-log-messages.md
Original file line number Diff line number Diff line change
@@ -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
12 changes: 9 additions & 3 deletions internal/grpc/interceptors/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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
}
Expand Down Expand Up @@ -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).
Expand All @@ -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
}
Expand Down

0 comments on commit ca8d796

Please sign in to comment.