mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdmain: move SetupLogging to embed
Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
This commit is contained in:
parent
4b1e09f2b4
commit
1fa295e3ba
@ -29,6 +29,7 @@ import (
|
||||
"github.com/coreos/etcd/pkg/flags"
|
||||
"github.com/coreos/etcd/pkg/types"
|
||||
"github.com/coreos/etcd/version"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
)
|
||||
|
||||
@ -80,7 +81,6 @@ type config struct {
|
||||
configFile string
|
||||
printVersion bool
|
||||
ignored []string
|
||||
logOutput string
|
||||
}
|
||||
|
||||
// configFlags has the set of flags used for command line parsing a Config
|
||||
@ -192,7 +192,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.")
|
||||
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.")
|
||||
|
@ -15,7 +15,6 @@
|
||||
package etcdmain
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@ -39,6 +38,7 @@ import (
|
||||
"github.com/coreos/etcd/pkg/types"
|
||||
"github.com/coreos/etcd/proxy/httpproxy"
|
||||
"github.com/coreos/etcd/version"
|
||||
|
||||
"github.com/coreos/pkg/capnslog"
|
||||
"github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
"google.golang.org/grpc"
|
||||
@ -69,7 +69,7 @@ func startEtcdOrProxyV2() {
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
setupLogging(cfg)
|
||||
cfg.Config.SetupLogging()
|
||||
|
||||
var stopped <-chan struct{}
|
||||
var errc <-chan error
|
||||
@ -387,41 +387,6 @@ func identifyDataDirOrDie(dir string) dirType {
|
||||
return dirEmpty
|
||||
}
|
||||
|
||||
func setupLogging(cfg *config) {
|
||||
cfg.ClientTLSInfo.HandshakeFailure = func(conn *tls.Conn, err error) {
|
||||
plog.Infof("rejected connection from %q (%v)", conn.RemoteAddr().String(), err)
|
||||
}
|
||||
cfg.PeerTLSInfo.HandshakeFailure = cfg.ClientTLSInfo.HandshakeFailure
|
||||
|
||||
capnslog.SetGlobalLogLevel(capnslog.INFO)
|
||||
if cfg.Debug {
|
||||
capnslog.SetGlobalLogLevel(capnslog.DEBUG)
|
||||
grpc.EnableTracing = true
|
||||
}
|
||||
if cfg.LogPkgLevels != "" {
|
||||
repoLog := capnslog.MustRepoLogger("github.com/coreos/etcd")
|
||||
settings, err := repoLog.ParseLogLevelConfig(cfg.LogPkgLevels)
|
||||
if err != nil {
|
||||
plog.Warningf("couldn't parse log level string: %s, continuing with default levels", err.Error())
|
||||
return
|
||||
}
|
||||
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() {
|
||||
// TODO qualify arm64
|
||||
if runtime.GOARCH == "amd64" || runtime.GOARCH == "ppc64le" {
|
||||
|
Loading…
x
Reference in New Issue
Block a user