[#493] logger: Abolish non-usable options
Change logger's encoding to `console`, time encoding to `ISO8601TimeEncoder` and leave all other options as they are in `zap.NewProductionConfig`. Remove default values of no longer existing options in node/ir config. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
737a9417d1
commit
d17526f8ac
3 changed files with 5 additions and 59 deletions
|
@ -34,11 +34,6 @@ func newConfig(path string) (*viper.Viper, error) {
|
||||||
|
|
||||||
func defaultConfiguration(cfg *viper.Viper) {
|
func defaultConfiguration(cfg *viper.Viper) {
|
||||||
cfg.SetDefault("logger.level", "info")
|
cfg.SetDefault("logger.level", "info")
|
||||||
cfg.SetDefault("logger.format", "console")
|
|
||||||
cfg.SetDefault("logger.trace_level", "fatal")
|
|
||||||
cfg.SetDefault("logger.no_disclaimer", false)
|
|
||||||
cfg.SetDefault("logger.sampling.initial", 1000)
|
|
||||||
cfg.SetDefault("logger.sampling.thereafter", 1000)
|
|
||||||
|
|
||||||
cfg.SetDefault("pprof.enabled", false)
|
cfg.SetDefault("pprof.enabled", false)
|
||||||
cfg.SetDefault("pprof.address", ":6060")
|
cfg.SetDefault("pprof.address", ":6060")
|
||||||
|
|
|
@ -53,10 +53,6 @@ import (
|
||||||
const (
|
const (
|
||||||
// logger keys
|
// logger keys
|
||||||
cfgLogLevel = "logger.level"
|
cfgLogLevel = "logger.level"
|
||||||
cfgLogFormat = "logger.format"
|
|
||||||
cfgLogTrace = "logger.trace_level"
|
|
||||||
cfgLogInitSampling = "logger.sampling.initial"
|
|
||||||
cfgLogThereafterSampling = "logger.sampling.thereafter"
|
|
||||||
|
|
||||||
// pprof keys
|
// pprof keys
|
||||||
cfgProfilerEnable = "pprof.enabled"
|
cfgProfilerEnable = "pprof.enabled"
|
||||||
|
@ -490,10 +486,6 @@ func defaultConfiguration(v *viper.Viper) {
|
||||||
v.SetDefault(cfgNetmapWorkerPoolSize, 10)
|
v.SetDefault(cfgNetmapWorkerPoolSize, 10)
|
||||||
|
|
||||||
v.SetDefault(cfgLogLevel, "info")
|
v.SetDefault(cfgLogLevel, "info")
|
||||||
v.SetDefault(cfgLogFormat, "console")
|
|
||||||
v.SetDefault(cfgLogTrace, "fatal")
|
|
||||||
v.SetDefault(cfgLogInitSampling, 1000)
|
|
||||||
v.SetDefault(cfgLogThereafterSampling, 1000)
|
|
||||||
|
|
||||||
v.SetDefault(cfgProfilerEnable, false)
|
v.SetDefault(cfgProfilerEnable, false)
|
||||||
v.SetDefault(cfgProfilerAddr, ":6060")
|
v.SetDefault(cfgProfilerAddr, ":6060")
|
||||||
|
|
|
@ -16,14 +16,6 @@ import (
|
||||||
// go.uber.org/zap.Logger.
|
// go.uber.org/zap.Logger.
|
||||||
type Logger = zap.Logger
|
type Logger = zap.Logger
|
||||||
|
|
||||||
const (
|
|
||||||
formatJSON = "json"
|
|
||||||
formatConsole = "console"
|
|
||||||
|
|
||||||
defaultSamplingInitial = 100
|
|
||||||
defaultSamplingThereafter = 100
|
|
||||||
)
|
|
||||||
|
|
||||||
// ErrNilLogger is returned by functions that
|
// ErrNilLogger is returned by functions that
|
||||||
// expect a non-nil Logger, but received nil.
|
// expect a non-nil Logger, but received nil.
|
||||||
var ErrNilLogger = errors.New("logger is nil")
|
var ErrNilLogger = errors.New("logger is nil")
|
||||||
|
@ -31,51 +23,18 @@ var ErrNilLogger = errors.New("logger is nil")
|
||||||
// NewLogger is a logger's constructor.
|
// NewLogger is a logger's constructor.
|
||||||
func NewLogger(v *viper.Viper) (*Logger, error) {
|
func NewLogger(v *viper.Viper) (*Logger, error) {
|
||||||
c := zap.NewProductionConfig()
|
c := zap.NewProductionConfig()
|
||||||
|
|
||||||
c.OutputPaths = []string{"stdout"}
|
|
||||||
c.ErrorOutputPaths = []string{"stdout"}
|
|
||||||
|
|
||||||
if v.IsSet("logger.sampling") {
|
|
||||||
c.Sampling = &zap.SamplingConfig{
|
|
||||||
Initial: defaultSamplingInitial,
|
|
||||||
Thereafter: defaultSamplingThereafter,
|
|
||||||
}
|
|
||||||
|
|
||||||
if val := v.GetInt("logger.sampling.initial"); val > 0 {
|
|
||||||
c.Sampling.Initial = val
|
|
||||||
}
|
|
||||||
|
|
||||||
if val := v.GetInt("logger.sampling.thereafter"); val > 0 {
|
|
||||||
c.Sampling.Thereafter = val
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// logger level
|
|
||||||
c.Level = safeLevel(v.GetString("logger.level"))
|
c.Level = safeLevel(v.GetString("logger.level"))
|
||||||
traceLvl := safeLevel(v.GetString("logger.trace_level"))
|
c.Encoding = "console"
|
||||||
|
|
||||||
// logger format
|
|
||||||
switch f := v.GetString("logger.format"); strings.ToLower(f) {
|
|
||||||
case formatConsole:
|
|
||||||
c.Encoding = formatConsole
|
|
||||||
default:
|
|
||||||
c.Encoding = formatJSON
|
|
||||||
}
|
|
||||||
|
|
||||||
// logger time
|
|
||||||
c.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
c.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
||||||
|
|
||||||
l, err := c.Build(
|
l, err := c.Build(
|
||||||
// enable trace only for current log-level
|
// record a stack trace for all messages at or above fatal level
|
||||||
zap.AddStacktrace(traceLvl))
|
zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel)),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.GetBool("logger.no_disclaimer") {
|
|
||||||
return l, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
name := v.GetString("app.name")
|
name := v.GetString("app.name")
|
||||||
version := v.GetString("app.version")
|
version := v.GetString("app.version")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue