Skip to content
Permalink
Browse files

Added JsonPbMarshalling interface (#236)

* Added a new JsonPbMarshal interface, used by the payload interceptors.

This allows overriding this functionality with something the user provides.

* Added better description on how the JsonPbMarshaller in payload interceptors can be overridden.
  • Loading branch information...
petervandenbroek authored and johanbrandhorst committed Sep 26, 2019
1 parent 52f080d commit c5238449d49bd6b747118be863d4907cbb963a63
Showing with 11 additions and 2 deletions.
  1. +7 −0 logging/common.go
  2. +2 −1 logging/logrus/payload_interceptors.go
  3. +2 −1 logging/zap/payload_interceptors.go
@@ -5,7 +5,9 @@ package grpc_logging

import (
"context"
"io"

"github.com/golang/protobuf/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
)
@@ -34,3 +36,8 @@ type ServerPayloadLoggingDecider func(ctx context.Context, fullMethodName string
// ClientPayloadLoggingDecider is a user-provided function for deciding whether to log the client-side
// request/response payloads
type ClientPayloadLoggingDecider func(ctx context.Context, fullMethodName string) bool

// JsonPbMarshaller is a marshaller that serializes protobuf messages.
type JsonPbMarshaler interface {
Marshal(out io.Writer, pb proto.Message) error
}
@@ -15,7 +15,8 @@ import (

var (
// JsonPbMarshaller is the marshaller used for serializing protobuf messages.
JsonPbMarshaller = &jsonpb.Marshaler{}
// If needed, this variable can be reassigned with a different marshaller with the same Marshal() signature.
JsonPbMarshaller grpc_logging.JsonPbMarshaler = &jsonpb.Marshaler{}
)

// PayloadUnaryServerInterceptor returns a new unary server interceptors that logs the payloads of requests.
@@ -16,7 +16,8 @@ import (

var (
// JsonPbMarshaller is the marshaller used for serializing protobuf messages.
JsonPbMarshaller = &jsonpb.Marshaler{}
// If needed, this variable can be reassigned with a different marshaller with the same Marshal() signature.
JsonPbMarshaller grpc_logging.JsonPbMarshaler = &jsonpb.Marshaler{}
)

// PayloadUnaryServerInterceptor returns a new unary server interceptors that logs the payloads of requests.

0 comments on commit c523844

Please sign in to comment.
You can’t perform that action at this time.