...

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

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

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

View as plain text