From c645781b9814470991adc2168e6b316004287659 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 21 May 2021 16:26:38 +0300 Subject: [PATCH] [#493] node/config: Implement logger section Create `logger` sub-package of `config` package. Implement `LoggerSection` type of logger sub-section. Add `Level` method to read logger level config value. Default level is `info`. Signed-off-by: Leonard Lyubich --- cmd/neofs-node/config/logger/config.go | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 cmd/neofs-node/config/logger/config.go diff --git a/cmd/neofs-node/config/logger/config.go b/cmd/neofs-node/config/logger/config.go new file mode 100644 index 000000000..479bf97c8 --- /dev/null +++ b/cmd/neofs-node/config/logger/config.go @@ -0,0 +1,33 @@ +package loggerconfig + +import ( + "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" +) + +// LoggerSection represents config section +// for logging component. +type LoggerSection config.Config + +// config defaults +const ( + // LevelDefault is a default logger level + LevelDefault = "info" +) + +// Init initializes LoggerSection from +// "logger" subsection of config. +func Init(root *config.Config) *LoggerSection { + return (*LoggerSection)(root.Sub("logger")) +} + +// Level returns configuration value with name "level". +// +// Returns LevelDefault if value is not a non-empty string. +func (x *LoggerSection) Level() string { + v := config.StringSafe((*config.Config)(x), "level") + if v != "" { + return v + } + + return LevelDefault +}