Skip to content

Commit

Permalink
Improve zap grpc logger documentation on verbosity levels (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdoherty4 authored Sep 20, 2021
1 parent b7b1ffc commit b6d97fa
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions logging/zap/grpclogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ func (l *zapGrpcLogger) Println(args ...interface{}) {
l.logger.Info(fmt.Sprint(args...))
}

// ReplaceGrpcLoggerV2 replaces the grpc_log.LoggerV2 with the provided logger.
// It should be called before any gRPC functions.
// ReplaceGrpcLoggerV2 replaces the grpclog.LoggerV2 with the provided logger.
// It should be called before any gRPC functions. Logging verbosity defaults to info level.
// To adjust gRPC logging verbosity, see ReplaceGrpcLoggerV2WithVerbosity.
func ReplaceGrpcLoggerV2(logger *zap.Logger) {
ReplaceGrpcLoggerV2WithVerbosity(logger, 0)
}

// ReplaceGrpcLoggerV2WithVerbosity replaces the grpc_.LoggerV2 with the provided logger and verbosity.
// ReplaceGrpcLoggerV2WithVerbosity replaces the grpclog.Logger with the provided logger and verbosity.
// It should be called before any gRPC functions.
// verbosity correlates to grpclogs verbosity levels. A higher verbosity value results in less logging.
func ReplaceGrpcLoggerV2WithVerbosity(logger *zap.Logger, verbosity int) {
zgl := &zapGrpcLoggerV2{
logger: logger.With(SystemField, zap.Bool("grpc_log", true)).WithOptions(zap.AddCallerSkip(2)),
Expand All @@ -63,7 +65,7 @@ func ReplaceGrpcLoggerV2WithVerbosity(logger *zap.Logger, verbosity int) {
grpclog.SetLoggerV2(zgl)
}

// SetGrpcLoggerV2 replaces the grpc_log.LoggerV2 with the provided logger.
// SetGrpcLoggerV2 replaces the grpc_log.Logger with the provided logger.
// It can be used even when grpc infrastructure was initialized.
func SetGrpcLoggerV2(settable grpc_logsettable.SettableLoggerV2, logger *zap.Logger) {
SetGrpcLoggerV2WithVerbosity(settable, logger, 0)
Expand Down

0 comments on commit b6d97fa

Please sign in to comment.