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

     1  /*
     2  `grpc_logrus` is a gRPC logging middleware backed by Logrus loggers
     3  
     4  It accepts a user-configured `logrus.Entry` that will be used for logging completed gRPC calls. The same
     5  `logrus.Entry` will be used for logging completed gRPC calls, and be populated into the `context.Context` passed into gRPC handler code.
     6  
     7  On calling `StreamServerInterceptor` or `UnaryServerInterceptor` this logging middleware will add gRPC call information
     8  to the ctx so that it will be present on subsequent use of the `ctxlogrus` logger.
     9  
    10  This package also implements request and response *payload* logging, both for server-side and client-side. These will be
    11  logged as structured `jsonpb` fields for every message received/sent (both unary and streaming). For that please use
    12  `Payload*Interceptor` functions for that. Please note that the user-provided function that determines whetether to log
    13  the full request/response payload needs to be written with care, this can significantly slow down gRPC.
    14  
    15  If a deadline is present on the gRPC request the grpc.request.deadline tag is populated when the request begins. grpc.request.deadline
    16  is a string representing the time (RFC3339) when the current call will expire.
    17  
    18  Logrus can also be made as a backend for gRPC library internals. For that use `ReplaceGrpcLogger`.
    19  
    20  *Server Interceptor*
    21  Below is a JSON formatted example of a log that would be logged by the server interceptor:
    22  
    23  	{
    24  	  "level": "info",					// string  logrus log levels
    25  	  "msg": "finished unary call",				// string  log message
    26  	  "grpc.code": "OK",					// string  grpc status code
    27  	  "grpc.method": "Ping",				// string  method name
    28  	  "grpc.service": "mwitkow.testproto.TestService",      // string  full name of the called service
    29  	  "grpc.start_time": "2006-01-02T15:04:05Z07:00",       // string  RFC3339 representation of the start time
    30  	  "grpc.request.deadline": "2006-01-02T15:04:05Z07:00",   // string  RFC3339 deadline of the current request if supplied
    31  	  "grpc.request.value": "something",			// string  value on the request
    32  	  "grpc.time_ms": 1.234,				// float32 run time of the call in ms
    33  	  "peer.address": {
    34  	    "IP": "127.0.0.1",					// string  IP address of calling party
    35  	    "Port": 60216,					// int     port call is coming in on
    36  	    "Zone": ""						// string  peer zone for caller
    37  	  },
    38  	  "span.kind": "server",				// string  client | server
    39  	  "system": "grpc"					// string
    40  
    41  	  "custom_field": "custom_value",			// string  user defined field
    42  	  "custom_tags.int": 1337,				// int     user defined tag on the ctx
    43  	  "custom_tags.string": "something",			// string  user defined tag on the ctx
    44  	}
    45  
    46  *Payload Interceptor*
    47  Below is a JSON formatted example of a log that would be logged by the payload interceptor:
    48  
    49  	{
    50  	  "level": "info",							// string logrus log levels
    51  	  "msg": "client request payload logged as grpc.request.content",   	// string log message
    52  
    53  	  "grpc.request.content": {						// object content of RPC request
    54  	    "value": "something",						// string defined by caller
    55  	    "sleepTimeMs": 9999							// int    defined by caller
    56  	  },
    57  	  "grpc.method": "Ping",						// string method being called
    58  	  "grpc.service": "mwitkow.testproto.TestService",			// string service being called
    59  	  "span.kind": "client",						// string client | server
    60  	  "system": "grpc"							// string
    61  	}
    62  
    63  Note - due to implementation ZAP differs from Logrus in the "grpc.request.content" object by having an inner "msg" object.
    64  
    65  Please see examples and tests for examples of use.
    66  */
    67  package grpc_logrus