etcdmain: configurable 'etcd' binary log-output

Fix https://github.com/coreos/etcd/issues/5449.
release-3.1
Gyu-Ho Lee 2016-11-03 12:30:25 -07:00
parent aa526cd53d
commit 6ffd7e3ed1
3 changed files with 17 additions and 0 deletions

View File

@ -75,6 +75,7 @@ type config struct {
configFile string
printVersion bool
ignored []string
logOutput string
}
// configFlags has the set of flags used for command line parsing a Config
@ -184,6 +185,7 @@ func newConfig() *config {
// logging
fs.BoolVar(&cfg.Debug, "debug", false, "Enable debug-level logging for etcd.")
fs.StringVar(&cfg.LogPkgLevels, "log-package-levels", "", "Specify a particular log level for each etcd package (eg: 'etcdmain=CRITICAL,etcdserver=DEBUG').")
fs.StringVar(&cfg.logOutput, "log-output", "default", "Specify 'stdout' or 'stderr' to skip journald logging even when running under systemd.")
// unsafe
fs.BoolVar(&cfg.ForceNewCluster, "force-new-cluster", false, "Force to create a new one member cluster.")

View File

@ -392,6 +392,19 @@ func setupLogging(cfg *config) {
}
repoLog.SetLogLevel(settings)
}
// capnslog initially SetFormatter(NewDefaultFormatter(os.Stderr))
// where NewDefaultFormatter returns NewJournaldFormatter when syscall.Getppid() == 1
// specify 'stdout' or 'stderr' to skip journald logging even when running under systemd
switch cfg.logOutput {
case "stdout":
capnslog.SetFormatter(capnslog.NewPrettyFormatter(os.Stdout, cfg.Debug))
case "stderr":
capnslog.SetFormatter(capnslog.NewPrettyFormatter(os.Stderr, cfg.Debug))
case "default":
default:
plog.Panicf(`unknown log-output %q (only supports "default", "stdout", "stderr")`, cfg.logOutput)
}
}
func checkSupportArch() {

View File

@ -139,6 +139,8 @@ logging flags
enable debug-level logging for etcd.
--log-package-levels ''
specify a particular log level for each etcd package (eg: 'etcdmain=CRITICAL,etcdserver=DEBUG').
--log-output 'default'
specify 'stdout' or 'stderr' to skip journald logging even when running under systemd.
unsafe flags: