Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set grpc logger to collector #4501

Merged
merged 11 commits into from
Dec 13, 2021
Prev Previous commit
Next Next commit
added comment
  • Loading branch information
pavankrish123 committed Dec 2, 2021
commit 4e19b878d9f310d09f0c0237a6b968de966ede5e
17 changes: 10 additions & 7 deletions service/internal/telemetrylogs/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,18 @@ func NewLogger(cfg config.ServiceTelemetryLogs, options []zap.Option) (*zap.Logg
return logger, nil
}

// SetGRPCLogger replaces grpc logger with collector logger. The minimum level of gRPC logs is
// set to WARN should the loglevel of the collector is set to INFO to avoid copious logging from grpc framework.
func SetGRPCLogger(logger *zap.Logger, loglevel zapcore.Level) {
glogger := logger.WithOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
// SetGRPCLogger replaces grpc logger with logger cloned from baseLogger with exact configuration.
// The minimum level of gRPC logs is set to WARN should the loglevel of the collector is set to INFO to avoid
// copious logging from grpc framework.
func SetGRPCLogger(baseLogger *zap.Logger, loglevel zapcore.Level) {
glogger := baseLogger.WithOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
var c zapcore.Core
if loglevel == zap.InfoLevel {
c, _ := zapcore.NewIncreaseLevelCore(core, zap.WarnLevel)
return c
c, _ = zapcore.NewIncreaseLevelCore(core, zap.WarnLevel)
jpkrohling marked this conversation as resolved.
Show resolved Hide resolved
} else {
c = core
}
return core
return c.With([]zapcore.Field{zap.Bool("grpc_log", true)})
}))
grpcSettableLogger.Set(zapgrpc.NewLogger(glogger))
}
1 change: 0 additions & 1 deletion service/internal/telemetrylogs/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func TestGRPCLogger(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
obsInfo, obsWarn := false, false

hook := zap.Hooks(func(entry zapcore.Entry) error {
switch entry.Level {
case zapcore.InfoLevel:
Expand Down