Skip to content

Commit

Permalink
etcdmain: configurable 'etcd' binary log-output
Browse files Browse the repository at this point in the history
Fix #5449.
  • Loading branch information
gyuho committed Nov 3, 2016
1 parent aa526cd commit 6ffd7e3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions etcdmain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.")
Expand Down
13 changes: 13 additions & 0 deletions etcdmain/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions etcdmain/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 6ffd7e3

Please sign in to comment.