embed: use /dev/null to discard server logs

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
Gyuho Lee 2018-04-17 06:13:24 -07:00
parent 0e4c8dcedc
commit a31c38f3b0
2 changed files with 3 additions and 13 deletions

View File

@ -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
}

View File

@ -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()