github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/go-grpc-middleware/logging/common.go (about)

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