Skip to content
/ etcd Public
forked from etcd-io/etcd

Commit

Permalink
*: configurable 'etcd' binary log-output
Browse files Browse the repository at this point in the history
  • Loading branch information
gyuho committed Nov 3, 2016
1 parent aa526cd commit d49cb83
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ type Config struct {

// debug

Debug bool `json:"debug"`
Debug bool `json:"debug"`
EnablePprof bool

// log

LogPkgLevels string `json:"log-package-levels"`
EnablePprof bool
LogOutput string `json:"log-output"`

// ForceNewCluster starts a new cluster even if previously started; unsafe.
ForceNewCluster bool `json:"force-new-cluster"`
Expand Down
1 change: 1 addition & 0 deletions etcdmain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,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", "", "Specify 'stdout' or 'stderr' to skip journald logging even when running under init (ppid == 1).")

// 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 init (ppid == 1)
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:
plog.Panicf(`unknown log-output %q (only supports "", "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 ''
specify 'stdout' or 'stderr' to skip journald logging even when running under init (ppid == 1).
unsafe flags:
Expand Down

0 comments on commit d49cb83

Please sign in to comment.