diff --git a/dm/master/config.go b/dm/master/config.go index a771658ff2..a444b0291e 100644 --- a/dm/master/config.go +++ b/dm/master/config.go @@ -439,7 +439,7 @@ func parseURLs(s string) ([]url.URL, error) { return urls, nil } -func genEmbedEtcdConfigWithLogger() *embed.Config { +func genEmbedEtcdConfigWithLogger(logLevel string) *embed.Config { cfg := embed.NewConfig() cfg.EnableGRPCGateway = true // enable gRPC gateway for the internal etcd. @@ -447,9 +447,13 @@ func genEmbedEtcdConfigWithLogger() *embed.Config { // NOTE: `genEmbedEtcdConfig` can only be called after logger initialized. // NOTE: if using zap logger for etcd, must build it before any concurrent gRPC calls, // otherwise, DATA RACE occur in NewZapCoreLoggerBuilder and gRPC. - // NOTE: we can only increase the log level for the clone logger but not decrease. - logger := log.L().WithFields(zap.String("component", "embed etcd")).WithOptions(zap.IncreaseLevel(zap.ErrorLevel)) - cfg.ZapLoggerBuilder = embed.NewZapCoreLoggerBuilder(logger, logger.Core(), log.Props().Syncer) // use global app props. + logger := log.L().WithFields(zap.String("component", "embed etcd")) + // if logLevel is info, set etcd log level to WARN to reduce log + if strings.ToLower(logLevel) == "info" { + logger.Logger = logger.WithOptions(zap.IncreaseLevel(zap.WarnLevel)) + } + + cfg.ZapLoggerBuilder = embed.NewZapCoreLoggerBuilder(logger.Logger, logger.Core(), log.Props().Syncer) // use global app props. cfg.Logger = "zap" // TODO: we run ZapLoggerBuilder to set SetLoggerV2 before we do some etcd operations diff --git a/dm/master/etcd_test.go b/dm/master/etcd_test.go index 39e7261c6b..b95368f3d6 100644 --- a/dm/master/etcd_test.go +++ b/dm/master/etcd_test.go @@ -55,7 +55,7 @@ func (t *testEtcdSuite) TestStartEtcdFail(c *check.C) { c.Assert(cfgCluster.adjust(), check.IsNil) // start an etcd cluster - cfgClusterEtcd := genEmbedEtcdConfigWithLogger() + cfgClusterEtcd := genEmbedEtcdConfigWithLogger("info") cfgClusterEtcd, err := cfgCluster.genEmbedEtcdConfig(cfgClusterEtcd) c.Assert(err, check.IsNil) e, err := startEtcd(cfgClusterEtcd, nil, nil, 3*time.Second) @@ -71,7 +71,7 @@ func (t *testEtcdSuite) TestPrepareJoinEtcd(c *check.C) { cfgCluster.AdvertiseAddr = tempurl.Alloc()[len("http://"):] cfgCluster.PeerUrls = tempurl.Alloc() c.Assert(cfgCluster.adjust(), check.IsNil) - cfgClusterEtcd := genEmbedEtcdConfigWithLogger() + cfgClusterEtcd := genEmbedEtcdConfigWithLogger("info") cfgClusterEtcd, err := cfgCluster.genEmbedEtcdConfig(cfgClusterEtcd) c.Assert(err, check.IsNil) @@ -178,7 +178,7 @@ func (t *testEtcdSuite) TestPrepareJoinEtcd(c *check.C) { c.Assert(err, check.ErrorMatches, ".*fail to join embed etcd: there is a member that has not joined successfully, continue the join or remove it.*") // start the joining etcd - cfgAfterEtcd := genEmbedEtcdConfigWithLogger() + cfgAfterEtcd := genEmbedEtcdConfigWithLogger("info") cfgAfterEtcd, err = cfgAfter.genEmbedEtcdConfig(cfgAfterEtcd) c.Assert(err, check.IsNil) e2, err := startEtcd(cfgAfterEtcd, nil, nil, etcdStartTimeout) diff --git a/dm/master/server.go b/dm/master/server.go index 6a6cf8b7c7..e4cb71d63e 100644 --- a/dm/master/server.go +++ b/dm/master/server.go @@ -140,7 +140,7 @@ func NewServer(cfg *Config) *Server { // Start starts to serving func (s *Server) Start(ctx context.Context) (err error) { - etcdCfg := genEmbedEtcdConfigWithLogger() + etcdCfg := genEmbedEtcdConfigWithLogger(s.cfg.LogLevel) // prepare config to join an existing cluster err = prepareJoinEtcd(s.cfg) if err != nil {