From 18b3e45e961fed3d0b97467db7a44ea2d381ce20 Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Mon, 16 Apr 2018 19:09:09 -0700 Subject: [PATCH] *: support --log-output=discard Signed-off-by: Gyuho Lee --- CHANGELOG-3.4.md | 1 + embed/config.go | 9 ++++++++- embed/config_test.go | 4 ++-- integration/embed_test.go | 4 ++-- snapshot/member_test.go | 2 +- snapshot/v3_snapshot_test.go | 6 +++--- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CHANGELOG-3.4.md b/CHANGELOG-3.4.md index bee83e549..aa7ddb1ce 100644 --- a/CHANGELOG-3.4.md +++ b/CHANGELOG-3.4.md @@ -144,6 +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. ### Added: `embed` diff --git a/embed/config.go b/embed/config.go index f56cddf41..2e958c2e9 100644 --- a/embed/config.go +++ b/embed/config.go @@ -421,18 +421,25 @@ func (cfg *Config) setupLogging() error { lcfg.OutputPaths = []string{"stderr"} lcfg.ErrorOutputPaths = []string{"stderr"} } + case "stderr": lcfg.OutputPaths = []string{"stderr"} lcfg.ErrorOutputPaths = []string{"stderr"} + case "stdout": lcfg.OutputPaths = []string{"stdout"} lcfg.ErrorOutputPaths = []string{"stdout"} - case "io-discard": // only for testing + + case "discard": // only for testing + lcfg.OutputPaths = []string{} + lcfg.ErrorOutputPaths = []string{} ignoreLog = true + default: lcfg.OutputPaths = []string{cfg.LogOutput} lcfg.ErrorOutputPaths = []string{cfg.LogOutput} } + if cfg.Debug { lcfg.Level = zap.NewAtomicLevelAt(zap.DebugLevel) grpc.EnableTracing = true diff --git a/embed/config_test.go b/embed/config_test.go index e199779af..cfcf77ada 100644 --- a/embed/config_test.go +++ b/embed/config_test.go @@ -41,7 +41,7 @@ func TestConfigFileOtherFields(t *testing.T) { ptls, true, "zap", - "io-discard", + "discard", 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 = "io-discard" + cfg.LogOutput = "discard" cfg.Debug = false cfg.AutoCompactionMode = "period" err := cfg.Validate() diff --git a/integration/embed_test.go b/integration/embed_test.go index f15da7678..b44298565 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 = "io-discard" + tests[i].cfg.LogOutput = "discard" 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 = "io-discard" + cfg.LogOutput = "discard" cfg.Debug = false cfg.ClusterState = "new" diff --git a/snapshot/member_test.go b/snapshot/member_test.go index 68d56d28d..6cec9aab0 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 = "io-discard" + cfg.LogOutput = "discard" cfg.Debug = false cfg.Name = "3" cfg.InitialClusterToken = testClusterTkn diff --git a/snapshot/v3_snapshot_test.go b/snapshot/v3_snapshot_test.go index 47b6d311b..12e665f6b 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 = "io-discard" + cfg.LogOutput = "discard" 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 = "io-discard" + cfg.LogOutput = "discard" 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 = "io-discard" + cfg.LogOutput = "discard" cfg.Debug = false cfg.Name = fmt.Sprintf("%d", i) cfg.InitialClusterToken = testClusterTkn