gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/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 "gitee.com/ks-custle/core-gm/grpc" 8 "gitee.com/ks-custle/core-gm/grpc/codes" 9 "gitee.com/ks-custle/core-gm/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