From 0e4c8dcedc9702abf84fb429397b2bd1d82121cd Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Tue, 17 Apr 2018 06:13:10 -0700 Subject: [PATCH 1/4] CHANGELOG-3.4: use "/dev/null" to ignore logs Signed-off-by: Gyuho Lee --- CHANGELOG-3.4.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG-3.4.md b/CHANGELOG-3.4.md index aa7ddb1ce..6ef2dc82e 100644 --- a/CHANGELOG-3.4.md +++ b/CHANGELOG-3.4.md @@ -144,7 +144,7 @@ See [security doc](https://github.com/coreos/etcd/blob/master/Documentation/op-g - e.g. `--logger=zap --log-output=default` will log server operations with [JSON-encoded format](TODO) and writes logs to `os.Stderr` (detect systemd journald TODO). - e.g. `--logger=zap --log-output=stderr` will log server operations with [JSON-encoded format](TODO) and writes logs to `os.Stderr` (bypass journald TODO). - e.g. `--logger=zap --log-output=stdout` will log server operations with [JSON-encoded format](TODO) and writes logs to `os.Stdout` (bypass journald TODO). - - e.g. `--logger=zap --log-output=discard` will discard all server logs. + - e.g. `--logger=zap --log-output=/dev/null` will discard all server logs. ### Added: `embed` From a31c38f3b0040b0d7296576415d073c95cfd290b Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Tue, 17 Apr 2018 06:13:24 -0700 Subject: [PATCH 2/4] embed: use /dev/null to discard server logs Signed-off-by: Gyuho Lee --- embed/config.go | 12 +----------- embed/config_test.go | 4 ++-- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/embed/config.go b/embed/config.go index 2e958c2e9..55e6a746e 100644 --- a/embed/config.go +++ b/embed/config.go @@ -405,7 +405,6 @@ func (cfg *Config) setupLogging() error { Encoding: "json", EncoderConfig: zap.NewProductionEncoderConfig(), } - ignoreLog := false switch cfg.LogOutput { case DefaultLogOutput: if syscall.Getppid() == 1 { @@ -430,11 +429,6 @@ func (cfg *Config) setupLogging() error { lcfg.OutputPaths = []string{"stdout"} lcfg.ErrorOutputPaths = []string{"stdout"} - case "discard": // only for testing - lcfg.OutputPaths = []string{} - lcfg.ErrorOutputPaths = []string{} - ignoreLog = true - default: lcfg.OutputPaths = []string{cfg.LogOutput} lcfg.ErrorOutputPaths = []string{cfg.LogOutput} @@ -446,11 +440,7 @@ func (cfg *Config) setupLogging() error { } var err error - if !ignoreLog { - cfg.logger, err = lcfg.Build() - } else { - cfg.logger = zap.NewNop() - } + cfg.logger, err = lcfg.Build() if err != nil { return err } diff --git a/embed/config_test.go b/embed/config_test.go index cfcf77ada..0012a28d2 100644 --- a/embed/config_test.go +++ b/embed/config_test.go @@ -41,7 +41,7 @@ func TestConfigFileOtherFields(t *testing.T) { ptls, true, "zap", - "discard", + "/dev/null", false, } @@ -157,7 +157,7 @@ func mustCreateCfgFile(t *testing.T, b []byte) *os.File { func TestAutoCompactionModeInvalid(t *testing.T) { cfg := NewConfig() cfg.Logger = "zap" - cfg.LogOutput = "discard" + cfg.LogOutput = "/dev/null" cfg.Debug = false cfg.AutoCompactionMode = "period" err := cfg.Validate() From 7c10c12ce796b528193ac2745101d5333662541c Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Tue, 17 Apr 2018 06:13:52 -0700 Subject: [PATCH 3/4] snapshot: use /dev/null to discard server logs Signed-off-by: Gyuho Lee --- snapshot/member_test.go | 2 +- snapshot/v3_snapshot_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/snapshot/member_test.go b/snapshot/member_test.go index 6cec9aab0..6e3608a16 100644 --- a/snapshot/member_test.go +++ b/snapshot/member_test.go @@ -64,7 +64,7 @@ func TestSnapshotV3RestoreMultiMemberAdd(t *testing.T) { cfg := embed.NewConfig() cfg.Logger = "zap" - cfg.LogOutput = "discard" + cfg.LogOutput = "/dev/null" cfg.Debug = false cfg.Name = "3" cfg.InitialClusterToken = testClusterTkn diff --git a/snapshot/v3_snapshot_test.go b/snapshot/v3_snapshot_test.go index 12e665f6b..e86762a06 100644 --- a/snapshot/v3_snapshot_test.go +++ b/snapshot/v3_snapshot_test.go @@ -44,7 +44,7 @@ func TestSnapshotV3RestoreSingle(t *testing.T) { cfg := embed.NewConfig() cfg.Logger = "zap" - cfg.LogOutput = "discard" + cfg.LogOutput = "/dev/null" cfg.Debug = false cfg.Name = "s1" cfg.InitialClusterToken = testClusterTkn @@ -153,7 +153,7 @@ func createSnapshotFile(t *testing.T, kvs []kv) string { cfg := embed.NewConfig() cfg.Logger = "zap" - cfg.LogOutput = "discard" + cfg.LogOutput = "/dev/null" cfg.Debug = false cfg.Name = "default" cfg.ClusterState = "new" @@ -220,7 +220,7 @@ func restoreCluster(t *testing.T, clusterN int, dbPath string) ( for i := 0; i < clusterN; i++ { cfg := embed.NewConfig() cfg.Logger = "zap" - cfg.LogOutput = "discard" + cfg.LogOutput = "/dev/null" cfg.Debug = false cfg.Name = fmt.Sprintf("%d", i) cfg.InitialClusterToken = testClusterTkn From 674388f59944c928ca55b90143c5f0924b7a2a43 Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Tue, 17 Apr 2018 06:14:03 -0700 Subject: [PATCH 4/4] integration: use /dev/null to discard server logs Signed-off-by: Gyuho Lee --- integration/embed_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration/embed_test.go b/integration/embed_test.go index b44298565..cd8cda949 100644 --- a/integration/embed_test.go +++ b/integration/embed_test.go @@ -53,7 +53,7 @@ func TestEmbedEtcd(t *testing.T) { for i := range tests { tests[i].cfg = *embed.NewConfig() tests[i].cfg.Logger = "zap" - tests[i].cfg.LogOutput = "discard" + tests[i].cfg.LogOutput = "/dev/null" tests[i].cfg.Debug = false } @@ -180,7 +180,7 @@ func newEmbedURLs(secure bool, n int) (urls []url.URL) { func setupEmbedCfg(cfg *embed.Config, curls []url.URL, purls []url.URL) { cfg.Logger = "zap" - cfg.LogOutput = "discard" + cfg.LogOutput = "/dev/null" cfg.Debug = false cfg.ClusterState = "new"