Browse Source

Merge pull request #9577 from gyuho/null

*: use /dev/null to discard server logs
Gyuho Lee 7 years ago
parent
commit
41b855a48e
6 changed files with 10 additions and 20 deletions
  1. 1 1
      CHANGELOG-3.4.md
  2. 1 11
      embed/config.go
  3. 2 2
      embed/config_test.go
  4. 2 2
      integration/embed_test.go
  5. 1 1
      snapshot/member_test.go
  6. 3 3
      snapshot/v3_snapshot_test.go

+ 1 - 1
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`
 

+ 1 - 11
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
 		}

+ 2 - 2
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()

+ 2 - 2
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"

+ 1 - 1
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

+ 3 - 3
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