Skip to content

Commit

Permalink
feat: use status.Code instead grpc.Code in log
Browse files Browse the repository at this point in the history
Signed-off-by: Matthis Holleville <matthish29@gmail.com>
  • Loading branch information
matthisholleville committed May 8, 2023
1 parent ac3057a commit 2c6cd11
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/server/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/status"
)

func logInterceptor(logger *zap.Logger) grpc.UnaryServerInterceptor {
Expand All @@ -29,13 +30,13 @@ func logInterceptor(logger *zap.Logger) grpc.UnaryServerInterceptor {
}

if err != nil {
fields = append(fields, zap.Int32("status_code", int32(grpc.Code(err))))
fields = append(fields, zap.Int32("status_code", int32(status.Code(err))))
}
message := "request completed"
if err != nil {
message = "request failed"
}
logRequest(logger, fields, int(grpc.Code(err)), message)
logRequest(logger, fields, int(status.Code(err)), message)

return response, err
}
Expand Down

0 comments on commit 2c6cd11

Please sign in to comment.