From 6ffd7e3ed1d506ebf3a30f6a396d38df3592daab Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Thu, 3 Nov 2016 12:30:25 -0700 Subject: [PATCH] etcdmain: configurable 'etcd' binary log-output Fix https://github.com/coreos/etcd/issues/5449. --- etcdmain/config.go | 2 ++ etcdmain/etcd.go | 13 +++++++++++++ etcdmain/help.go | 2 ++ 3 files changed, 17 insertions(+) diff --git a/etcdmain/config.go b/etcdmain/config.go index 5fb4dea4934..816bf729b41 100644 --- a/etcdmain/config.go +++ b/etcdmain/config.go @@ -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.") diff --git a/etcdmain/etcd.go b/etcdmain/etcd.go index f30d8b59eba..fa6de32e05a 100644 --- a/etcdmain/etcd.go +++ b/etcdmain/etcd.go @@ -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() { diff --git a/etcdmain/help.go b/etcdmain/help.go index e425a90cd36..b2fc579d629 100644 --- a/etcdmain/help.go +++ b/etcdmain/help.go @@ -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: