Browse Source

Merge pull request #11081 from gyuho/zap

*: fix zap logger --log-outputs without "stderr"
Gyuho Lee 6 years ago
parent
commit
9da9221d3f
2 changed files with 6 additions and 9 deletions
  1. 4 1
      embed/config_logging.go
  2. 2 8
      pkg/logutil/zap.go

+ 4 - 1
embed/config_logging.go

@@ -170,7 +170,10 @@ func (cfg *Config) setupLogging() error {
 		}
 		}
 
 
 		if !isJournal {
 		if !isJournal {
-			copied := logutil.AddOutputPaths(logutil.DefaultZapLoggerConfig, outputPaths, errOutputPaths)
+			copied := logutil.DefaultZapLoggerConfig
+			copied.OutputPaths = outputPaths
+			copied.ErrorOutputPaths = errOutputPaths
+			copied = logutil.MergeOutputPaths(copied)
 			copied.Level = zap.NewAtomicLevelAt(logutil.ConvertToZapLevel(cfg.LogLevel))
 			copied.Level = zap.NewAtomicLevelAt(logutil.ConvertToZapLevel(cfg.LogLevel))
 			if cfg.Debug || cfg.LogLevel == "debug" {
 			if cfg.Debug || cfg.LogLevel == "debug" {
 				// enable tracing even when "--debug --log-level info"
 				// enable tracing even when "--debug --log-level info"

+ 2 - 8
pkg/logutil/zap.go

@@ -53,15 +53,12 @@ var DefaultZapLoggerConfig = zap.Config{
 	ErrorOutputPaths: []string{"stderr"},
 	ErrorOutputPaths: []string{"stderr"},
 }
 }
 
 
-// AddOutputPaths adds output paths to the existing output paths, resolving conflicts.
-func AddOutputPaths(cfg zap.Config, outputPaths, errorOutputPaths []string) zap.Config {
+// MergeOutputPaths merges logging output paths, resolving conflicts.
+func MergeOutputPaths(cfg zap.Config) zap.Config {
 	outputs := make(map[string]struct{})
 	outputs := make(map[string]struct{})
 	for _, v := range cfg.OutputPaths {
 	for _, v := range cfg.OutputPaths {
 		outputs[v] = struct{}{}
 		outputs[v] = struct{}{}
 	}
 	}
-	for _, v := range outputPaths {
-		outputs[v] = struct{}{}
-	}
 	outputSlice := make([]string, 0)
 	outputSlice := make([]string, 0)
 	if _, ok := outputs["/dev/null"]; ok {
 	if _, ok := outputs["/dev/null"]; ok {
 		// "/dev/null" to discard all
 		// "/dev/null" to discard all
@@ -78,9 +75,6 @@ func AddOutputPaths(cfg zap.Config, outputPaths, errorOutputPaths []string) zap.
 	for _, v := range cfg.ErrorOutputPaths {
 	for _, v := range cfg.ErrorOutputPaths {
 		errOutputs[v] = struct{}{}
 		errOutputs[v] = struct{}{}
 	}
 	}
-	for _, v := range errorOutputPaths {
-		errOutputs[v] = struct{}{}
-	}
 	errOutputSlice := make([]string, 0)
 	errOutputSlice := make([]string, 0)
 	if _, ok := errOutputs["/dev/null"]; ok {
 	if _, ok := errOutputs["/dev/null"]; ok {
 		// "/dev/null" to discard all
 		// "/dev/null" to discard all