...

Source file src/github.com/grpc-ecosystem/go-grpc-middleware/logging/common.go

Documentation: github.com/grpc-ecosystem/go-grpc-middleware/logging

     1  // Copyright 2017 Michal Witkowski. All Rights Reserved.
     2  // See LICENSE for licensing terms.
     3  
     4  package grpc_logging
     5  
     6  import (
     7  	"context"
     8  	"io"
     9  
    10  	"github.com/golang/protobuf/proto"
    11  	"google.golang.org/grpc/codes"
    12  	"google.golang.org/grpc/status"
    13  )
    14  
    15  // ErrorToCode function determines the error code of an error
    16  // This makes using custom errors with grpc middleware easier
    17  type ErrorToCode func(err error) codes.Code
    18  
    19  func DefaultErrorToCode(err error) codes.Code {
    20  	return status.Code(err)
    21  }
    22  
    23  // Decider function defines rules for suppressing any interceptor logs
    24  type Decider func(fullMethodName string, err error) bool
    25  
    26  // DefaultDeciderMethod is the default implementation of decider to see if you should log the call
    27  // by default this if always true so all calls are logged
    28  func DefaultDeciderMethod(fullMethodName string, err error) bool {
    29  	return true
    30  }
    31  
    32  // ServerPayloadLoggingDecider is a user-provided function for deciding whether to log the server-side
    33  // request/response payloads
    34  type ServerPayloadLoggingDecider func(ctx context.Context, fullMethodName string, servingObject interface{}) bool
    35  
    36  // ClientPayloadLoggingDecider is a user-provided function for deciding whether to log the client-side
    37  // request/response payloads
    38  type ClientPayloadLoggingDecider func(ctx context.Context, fullMethodName string) bool
    39  
    40  // JsonPbMarshaller is a marshaller that serializes protobuf messages.
    41  type JsonPbMarshaler interface {
    42  	Marshal(out io.Writer, pb proto.Message) error
    43  }
    44  

View as plain text