mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
embed: add "LogLevel", deprecate "Debug" in v3.5
Make log level configurable, and deprecate "debug" flag in v3.5. And adds more warnings on flags that's being deprecated in v3.5. Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
This commit is contained in:
parent
e911f901a6
commit
b9de4bddda
@ -30,6 +30,7 @@ import (
|
||||
"go.etcd.io/etcd/etcdserver"
|
||||
"go.etcd.io/etcd/etcdserver/api/v3compactor"
|
||||
"go.etcd.io/etcd/pkg/flags"
|
||||
"go.etcd.io/etcd/pkg/logutil"
|
||||
"go.etcd.io/etcd/pkg/netutil"
|
||||
"go.etcd.io/etcd/pkg/srv"
|
||||
"go.etcd.io/etcd/pkg/tlsutil"
|
||||
@ -291,11 +292,8 @@ type Config struct {
|
||||
// Logger is logger options: "zap", "capnslog".
|
||||
// WARN: "capnslog" is being deprecated in v3.5.
|
||||
Logger string `json:"logger"`
|
||||
|
||||
// DeprecatedLogOutput is to be deprecated in v3.5.
|
||||
// Just here for safe migration in v3.4.
|
||||
DeprecatedLogOutput []string `json:"log-output"`
|
||||
|
||||
// LogLevel configures log level. Only supports debug, info, warn, error, panic, or fatal. Default 'info'.
|
||||
LogLevel string `json:"log-level"`
|
||||
// LogOutputs is either:
|
||||
// - "default" as os.Stderr,
|
||||
// - "stderr" as os.Stderr,
|
||||
@ -304,9 +302,6 @@ type Config struct {
|
||||
// It can be multiple when "Logger" is zap.
|
||||
LogOutputs []string `json:"log-outputs"`
|
||||
|
||||
// Debug is true, to enable debug level logging.
|
||||
Debug bool `json:"debug"`
|
||||
|
||||
// zapLoggerBuilder is used to build the zap logger.
|
||||
zapLoggerBuilder func(*Config) error
|
||||
|
||||
@ -329,6 +324,12 @@ type Config struct {
|
||||
|
||||
// TO BE DEPRECATED
|
||||
|
||||
// DeprecatedLogOutput is to be deprecated in v3.5.
|
||||
// Just here for safe migration in v3.4.
|
||||
DeprecatedLogOutput []string `json:"log-output"`
|
||||
// Debug is true, to enable debug level logging.
|
||||
// WARNING: to be deprecated in 3.5. Use "--log-level=debug" instead.
|
||||
Debug bool `json:"debug"`
|
||||
// LogPkgLevels is being deprecated in v3.5.
|
||||
// Only valid if "logger" option is "capnslog".
|
||||
// WARN: DO NOT USE THIS!
|
||||
@ -415,6 +416,7 @@ func NewConfig() *Config {
|
||||
DeprecatedLogOutput: []string{DefaultLogOutput},
|
||||
LogOutputs: []string{DefaultLogOutput},
|
||||
Debug: false,
|
||||
LogLevel: logutil.DefaultLogLevel,
|
||||
LogPkgLevels: "",
|
||||
}
|
||||
cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name)
|
||||
|
@ -69,11 +69,25 @@ func (cfg *Config) setupLogging() error {
|
||||
return fmt.Errorf("'--log-output=%q' and '--log-outputs=%q' are incompatible; only set --log-outputs", cfg.DeprecatedLogOutput, cfg.LogOutputs)
|
||||
}
|
||||
if !reflect.DeepEqual(cfg.DeprecatedLogOutput, []string{DefaultLogOutput}) {
|
||||
fmt.Fprintf(os.Stderr, "Deprecated '--log-output' flag is set to %q\n", cfg.DeprecatedLogOutput)
|
||||
fmt.Fprintf(os.Stderr, "[WARNING] Deprecated '--log-output' flag is set to %q\n", cfg.DeprecatedLogOutput)
|
||||
fmt.Fprintln(os.Stderr, "Please use '--log-outputs' flag")
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: remove after deprecating log related flags in v3.5
|
||||
if cfg.Debug {
|
||||
fmt.Fprintf(os.Stderr, "[WARNING] Deprecated '--debug' flag is set to %v (use '--log-level=debug' instead\n", cfg.Debug)
|
||||
}
|
||||
if cfg.Debug && cfg.LogLevel != "debug" {
|
||||
fmt.Fprintf(os.Stderr, "[WARNING] Deprecated '--debug' flag is set to %v with inconsistent '--log-level=%s' flag\n", cfg.Debug, cfg.LogLevel)
|
||||
}
|
||||
if cfg.Logger == "capnslog" {
|
||||
fmt.Fprintf(os.Stderr, "[WARNING] Deprecated '--logger=%s' flag is set; use '--logger=zap' flag instead\n", cfg.Logger)
|
||||
}
|
||||
if cfg.LogPkgLevels != "" {
|
||||
fmt.Fprintf(os.Stderr, "[WARNING] Deprecated '--log-package-levels=%s' flag is set; use '--logger=zap' flag instead\n", cfg.LogPkgLevels)
|
||||
}
|
||||
|
||||
switch cfg.Logger {
|
||||
case "capnslog": // TODO: deprecate this in v3.5
|
||||
cfg.ClientTLSInfo.HandshakeFailure = logTLSHandshakeFailure
|
||||
@ -85,7 +99,7 @@ func (cfg *Config) setupLogging() error {
|
||||
// enable info, warning, error
|
||||
grpclog.SetLoggerV2(grpclog.NewLoggerV2(os.Stderr, os.Stderr, os.Stderr))
|
||||
} else {
|
||||
capnslog.SetGlobalLogLevel(capnslog.INFO)
|
||||
capnslog.SetGlobalLogLevel(logutil.ConvertToCapnslogLogLevel(cfg.LogLevel))
|
||||
// only discard info
|
||||
grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, os.Stderr, os.Stderr))
|
||||
}
|
||||
@ -157,9 +171,11 @@ func (cfg *Config) setupLogging() error {
|
||||
|
||||
if !isJournal {
|
||||
copied := logutil.AddOutputPaths(logutil.DefaultZapLoggerConfig, outputPaths, errOutputPaths)
|
||||
|
||||
if cfg.Debug {
|
||||
copied.Level = zap.NewAtomicLevelAt(zap.DebugLevel)
|
||||
copied.Level = zap.NewAtomicLevelAt(logutil.ConvertToZapLevel(cfg.LogLevel))
|
||||
if cfg.Debug || cfg.LogLevel == "debug" {
|
||||
// enable tracing even when "--debug --log-level info"
|
||||
// in order to keep backward compatibility with <= v3.3
|
||||
// TODO: remove "Debug" check in v3.5
|
||||
grpc.EnableTracing = true
|
||||
}
|
||||
if cfg.zapLoggerBuilder == nil {
|
||||
@ -201,9 +217,11 @@ func (cfg *Config) setupLogging() error {
|
||||
return lerr
|
||||
}
|
||||
|
||||
lvl := zap.NewAtomicLevelAt(zap.InfoLevel)
|
||||
if cfg.Debug {
|
||||
lvl = zap.NewAtomicLevelAt(zap.DebugLevel)
|
||||
lvl := zap.NewAtomicLevelAt(logutil.ConvertToZapLevel(cfg.LogLevel))
|
||||
if cfg.Debug || cfg.LogLevel == "debug" {
|
||||
// enable tracing even when "--debug --log-level info"
|
||||
// in order to keep backward compatibility with <= v3.3
|
||||
// TODO: remove "Debug" check in v3.5
|
||||
grpc.EnableTracing = true
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user