From 3b797d7957003dec5f0a57a464549b302311a5a9 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 21 May 2021 21:03:47 +0300 Subject: [PATCH] [#493] node/config/logger: Simplify approach to read the level Dedicated type `LoggerSection` turned out to be redundant since it doesn't do a hidden logic and just uses `config.Config` API. Remove `LoggerSection` type and implement `Level` which do the same. Signed-off-by: Leonard Lyubich --- cmd/neofs-node/config/logger/config.go | 20 +++++++------------- cmd/neofs-node/config/logger/config_test.go | 20 ++++++-------------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/cmd/neofs-node/config/logger/config.go b/cmd/neofs-node/config/logger/config.go index 479bf97c8..e443020ed 100644 --- a/cmd/neofs-node/config/logger/config.go +++ b/cmd/neofs-node/config/logger/config.go @@ -4,27 +4,21 @@ 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". +// Level returns value of "level" config parameter +// from "logger" section. // // Returns LevelDefault if value is not a non-empty string. -func (x *LoggerSection) Level() string { - v := config.StringSafe((*config.Config)(x), "level") +func Level(c *config.Config) string { + v := config.StringSafe( + c.Sub("logger"), + "level", + ) if v != "" { return v } diff --git a/cmd/neofs-node/config/logger/config_test.go b/cmd/neofs-node/config/logger/config_test.go index 6258bed9b..fbdea6555 100644 --- a/cmd/neofs-node/config/logger/config_test.go +++ b/cmd/neofs-node/config/logger/config_test.go @@ -12,20 +12,13 @@ import ( ) func TestLoggerSection_Level(t *testing.T) { - checkLevel := func(c *loggerconfig.LoggerSection, expected string) { - lvl := c.Level() - require.Equal(t, expected, lvl) - } - configtest.ForEachFileType("../../../../config/example/node", func(c *config.Config) { - cfg := loggerconfig.Init(c) - - checkLevel(cfg, "debug") + v := loggerconfig.Level(c) + require.Equal(t, "debug", v) }) - empty := loggerconfig.Init(configtest.EmptyConfig()) - - checkLevel(empty, loggerconfig.LevelDefault) + v := loggerconfig.Level(configtest.EmptyConfig()) + require.Equal(t, loggerconfig.LevelDefault, v) t.Run("ENV", func(t *testing.T) { // TODO: read from file @@ -35,8 +28,7 @@ func TestLoggerSection_Level(t *testing.T) { ) require.NoError(t, err) - empty = loggerconfig.Init(configtest.EmptyConfig()) - - checkLevel(empty, "debug") + v := loggerconfig.Level(configtest.EmptyConfig()) + require.Equal(t, "debug", v) }) }