Skip to content

philip-bui/grpc-zerolog

Repository files navigation

gRPC Zerolog

BuildStatus Widget CodeCov Widget GoReport Widget GoDoc Widget

Implementation of gRPC Logging Middleware, integrating Zerolog as a gRPC Interceptor to log the following fields:

  • Request Protobufs as JSON.
  • Response Protobufs as JSON, or Errors.
  • Status Code, Duration, Timestamp, Service Name, Service Method, IP, Metadata Fields and User Agent.

Usage

import (
	"github.com/philip-bui/grpc-zerolog"
)

func main() {
	// With global Zerolog logger.
	grpc.NewServer(
		zerolog.UnaryInterceptor(),
	)

	// With custom Zerolog instance.
	log := zerolog.New(os.Stdout)
	grpc.NewServer(
		zerolog.UnaryInterceptorWithLogger(&log),
	)
}

License

gRPC Zerolog is available under the MIT license. See LICENSE for details.