From 6062f296034aba72bdcf29ba55812d025d6faeeb Mon Sep 17 00:00:00 2001 From: yifan Date: Tue, 15 Jun 2021 22:31:58 +0800 Subject: [PATCH] fix null pointer --- util/logutil/log.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/util/logutil/log.go b/util/logutil/log.go index 1a7b41ade9208..d99227e364e77 100644 --- a/util/logutil/log.go +++ b/util/logutil/log.go @@ -142,7 +142,7 @@ func initGRPCLogger(cfg *LogConfig) error { } func deepcopyLogConfig(o *log.Config) *log.Config { - return &log.Config{ + c := &log.Config{ Level: o.Level, Format: o.Format, DisableTimestamp: o.DisableTimestamp, @@ -156,12 +156,15 @@ func deepcopyLogConfig(o *log.Config) *log.Config { DisableCaller: o.DisableCaller, DisableStacktrace: o.DisableStacktrace, DisableErrorVerbose: o.DisableErrorVerbose, - Sampling: &zap.SamplingConfig{ + } + if o.Sampling != nil { + c.Sampling = &zap.SamplingConfig{ Initial: o.Sampling.Initial, Thereafter: o.Sampling.Thereafter, Hook: o.Sampling.Hook, - }, + } } + return c } // InitZapLogger is delegated to InitLogger.