mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
embed: do not support "--log-outputs=default" for zap logger
systemd/journal should be configured manually. Interpreting PPID 1 as systemd unit is wrong, especially when embedded etcd runs under Docker container. For such case, every single log write will error and fall back to stderr, which is inefficient. Instead, add "systemd/journal" log output option and returns error if systemd/journal socket cannot be found. "--logger=zap --log-outputs=default" will only error for v3.4, since zap logger is still experimental. v3.5 deprecates capnslog and changes "--log-outputs" default value to "--log-outputs=stderr". Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
parent
3a80499da4
commit
15fcd6d599
@ -59,6 +59,9 @@ const (
|
|||||||
DefaultListenClientURLs = "http://localhost:2379"
|
DefaultListenClientURLs = "http://localhost:2379"
|
||||||
|
|
||||||
DefaultLogOutput = "default"
|
DefaultLogOutput = "default"
|
||||||
|
JournalLogOutput = "systemd/journal"
|
||||||
|
StdErrLogOutput = "stderr"
|
||||||
|
StdOutLogOutput = "stdout"
|
||||||
|
|
||||||
// DefaultStrictReconfigCheck is the default value for "--strict-reconfig-check" flag.
|
// DefaultStrictReconfigCheck is the default value for "--strict-reconfig-check" flag.
|
||||||
// It's enabled by default.
|
// It's enabled by default.
|
||||||
|
@ -23,7 +23,6 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/coreos/etcd/pkg/logutil"
|
"github.com/coreos/etcd/pkg/logutil"
|
||||||
|
|
||||||
@ -112,13 +111,13 @@ func (cfg *Config) setupLogging() error {
|
|||||||
// specify 'stdout' or 'stderr' to skip journald logging even when running under systemd
|
// specify 'stdout' or 'stderr' to skip journald logging even when running under systemd
|
||||||
output := cfg.LogOutputs[0]
|
output := cfg.LogOutputs[0]
|
||||||
switch output {
|
switch output {
|
||||||
case "stdout":
|
case StdErrLogOutput:
|
||||||
capnslog.SetFormatter(capnslog.NewPrettyFormatter(os.Stdout, cfg.Debug))
|
|
||||||
case "stderr":
|
|
||||||
capnslog.SetFormatter(capnslog.NewPrettyFormatter(os.Stderr, cfg.Debug))
|
capnslog.SetFormatter(capnslog.NewPrettyFormatter(os.Stderr, cfg.Debug))
|
||||||
|
case StdOutLogOutput:
|
||||||
|
capnslog.SetFormatter(capnslog.NewPrettyFormatter(os.Stdout, cfg.Debug))
|
||||||
case DefaultLogOutput:
|
case DefaultLogOutput:
|
||||||
default:
|
default:
|
||||||
plog.Panicf(`unknown log-output %q (only supports %q, "stdout", "stderr")`, output, DefaultLogOutput)
|
plog.Panicf(`unknown log-output %q (only supports %q, %q, %q)`, output, DefaultLogOutput, StdErrLogOutput, StdOutLogOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
case "zap":
|
case "zap":
|
||||||
@ -147,30 +146,24 @@ func (cfg *Config) setupLogging() error {
|
|||||||
OutputPaths: make([]string, 0),
|
OutputPaths: make([]string, 0),
|
||||||
ErrorOutputPaths: make([]string, 0),
|
ErrorOutputPaths: make([]string, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
outputPaths, errOutputPaths := make(map[string]struct{}), make(map[string]struct{})
|
outputPaths, errOutputPaths := make(map[string]struct{}), make(map[string]struct{})
|
||||||
isJournald := false
|
isJournal := false
|
||||||
for _, v := range cfg.LogOutputs {
|
for _, v := range cfg.LogOutputs {
|
||||||
switch v {
|
switch v {
|
||||||
case DefaultLogOutput:
|
case DefaultLogOutput:
|
||||||
if syscall.Getppid() == 1 {
|
return errors.New("'--log-outputs=default' is not supported for v3.4 during zap logger migraion (use 'journal', 'stderr', 'stdout', etc.)")
|
||||||
// capnslog initially SetFormatter(NewDefaultFormatter(os.Stderr))
|
|
||||||
// where "NewDefaultFormatter" returns "NewJournaldFormatter"
|
|
||||||
// specify 'stdout' or 'stderr' to override this redirects
|
|
||||||
// when syscall.Getppid() == 1
|
|
||||||
isJournald = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
outputPaths["stderr"] = struct{}{}
|
case JournalLogOutput:
|
||||||
errOutputPaths["stderr"] = struct{}{}
|
isJournal = true
|
||||||
|
|
||||||
case "stderr":
|
case StdErrLogOutput:
|
||||||
outputPaths["stderr"] = struct{}{}
|
outputPaths[StdErrLogOutput] = struct{}{}
|
||||||
errOutputPaths["stderr"] = struct{}{}
|
errOutputPaths[StdErrLogOutput] = struct{}{}
|
||||||
|
|
||||||
case "stdout":
|
case StdOutLogOutput:
|
||||||
outputPaths["stdout"] = struct{}{}
|
outputPaths[StdOutLogOutput] = struct{}{}
|
||||||
errOutputPaths["stdout"] = struct{}{}
|
errOutputPaths[StdOutLogOutput] = struct{}{}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
outputPaths[v] = struct{}{}
|
outputPaths[v] = struct{}{}
|
||||||
@ -178,7 +171,7 @@ func (cfg *Config) setupLogging() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isJournald {
|
if !isJournal {
|
||||||
for v := range outputPaths {
|
for v := range outputPaths {
|
||||||
lcfg.OutputPaths = append(lcfg.OutputPaths, v)
|
lcfg.OutputPaths = append(lcfg.OutputPaths, v)
|
||||||
}
|
}
|
||||||
@ -219,7 +212,7 @@ func (cfg *Config) setupLogging() error {
|
|||||||
if len(cfg.LogOutputs) > 1 {
|
if len(cfg.LogOutputs) > 1 {
|
||||||
for _, v := range cfg.LogOutputs {
|
for _, v := range cfg.LogOutputs {
|
||||||
if v != DefaultLogOutput {
|
if v != DefaultLogOutput {
|
||||||
return fmt.Errorf("running as a systemd unit but other '--log-output' values (%q) are configured with 'default'; override 'default' value with something else", cfg.LogOutputs)
|
return fmt.Errorf("running with systemd/journal but other '--log-outputs' values (%q) are configured with 'default'; override 'default' value with something else", cfg.LogOutputs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user