From eadbb20ab24c4fc5c97f998bc77f916c8d98ec30 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Thu, 8 Jan 2026 13:22:58 +0100 Subject: [PATCH] consolidate log config in settings Signed-off-by: Christian Richter --- services/settings/pkg/command/health.go | 4 ++-- services/settings/pkg/command/server.go | 4 ++-- services/settings/pkg/config/config.go | 4 ++-- .../pkg/config/defaults/defaultconfig.go | 12 ++---------- services/settings/pkg/config/log.go | 9 --------- services/settings/pkg/logging/logging.go | 17 ----------------- services/settings/pkg/store/metadata/store.go | 11 +++-------- 7 files changed, 11 insertions(+), 50 deletions(-) delete mode 100644 services/settings/pkg/config/log.go delete mode 100644 services/settings/pkg/logging/logging.go diff --git a/services/settings/pkg/command/health.go b/services/settings/pkg/command/health.go index be648868b..ab39debae 100644 --- a/services/settings/pkg/command/health.go +++ b/services/settings/pkg/command/health.go @@ -5,9 +5,9 @@ import ( "net/http" "github.com/opencloud-eu/opencloud/pkg/config/configlog" + "github.com/opencloud-eu/opencloud/pkg/log" "github.com/opencloud-eu/opencloud/services/settings/pkg/config" "github.com/opencloud-eu/opencloud/services/settings/pkg/config/parser" - "github.com/opencloud-eu/opencloud/services/settings/pkg/logging" "github.com/spf13/cobra" ) @@ -21,7 +21,7 @@ func Health(cfg *config.Config) *cobra.Command { return configlog.ReturnError(parser.ParseConfig(cfg)) }, RunE: func(cmd *cobra.Command, args []string) error { - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := log.Configure(cfg.Service.Name, cfg.Commons, cfg.LogLevel) resp, err := http.Get( fmt.Sprintf( diff --git a/services/settings/pkg/command/server.go b/services/settings/pkg/command/server.go index dc889f053..3a81994b0 100644 --- a/services/settings/pkg/command/server.go +++ b/services/settings/pkg/command/server.go @@ -6,13 +6,13 @@ import ( "os/signal" "github.com/opencloud-eu/opencloud/pkg/config/configlog" + "github.com/opencloud-eu/opencloud/pkg/log" "github.com/opencloud-eu/opencloud/pkg/runner" ogrpc "github.com/opencloud-eu/opencloud/pkg/service/grpc" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/settings/pkg/config" "github.com/opencloud-eu/opencloud/services/settings/pkg/config/parser" - "github.com/opencloud-eu/opencloud/services/settings/pkg/logging" "github.com/opencloud-eu/opencloud/services/settings/pkg/metrics" "github.com/opencloud-eu/opencloud/services/settings/pkg/server/debug" "github.com/opencloud-eu/opencloud/services/settings/pkg/server/grpc" @@ -31,7 +31,7 @@ func Server(cfg *config.Config) *cobra.Command { return configlog.ReturnFatal(parser.ParseConfig(cfg)) }, RunE: func(cmd *cobra.Command, args []string) error { - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := log.Configure(cfg.Service.Name, cfg.Commons, cfg.LogLevel) traceProvider, err := tracing.GetTraceProvider(cmd.Context(), cfg.Commons.TracesExporter, cfg.Service.Name) if err != nil { return err diff --git a/services/settings/pkg/config/config.go b/services/settings/pkg/config/config.go index 17305a390..d4ba71e3c 100644 --- a/services/settings/pkg/config/config.go +++ b/services/settings/pkg/config/config.go @@ -15,8 +15,8 @@ type Config struct { Service Service `yaml:"-"` - Log *Log `yaml:"log"` - Debug Debug `yaml:"debug"` + LogLevel string `yaml:"loglevel" env:"OC_LOG_LEVEL;SETTINGS_LOG_LEVEL" desc:"The log level. Valid values are: 'panic', 'fatal', 'error', 'warn', 'info', 'debug', 'trace'." introductionVersion:"1.0.0"` + Debug Debug `yaml:"debug"` HTTP HTTP `yaml:"http"` GRPC GRPCConfig `yaml:"grpc"` diff --git a/services/settings/pkg/config/defaults/defaultconfig.go b/services/settings/pkg/config/defaults/defaultconfig.go index b2c1df408..d881be54d 100644 --- a/services/settings/pkg/config/defaults/defaultconfig.go +++ b/services/settings/pkg/config/defaults/defaultconfig.go @@ -69,16 +69,8 @@ func DefaultConfig() *config.Config { // EnsureDefaults adds default values to the configuration if they are not set yet func EnsureDefaults(cfg *config.Config) { - // provide with defaults for shared logging, since we need a valid destination address for "envdecode". - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil { - cfg.Log = &config.Log{} + if cfg.LogLevel == "" { + cfg.LogLevel = "error" } if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil { diff --git a/services/settings/pkg/config/log.go b/services/settings/pkg/config/log.go deleted file mode 100644 index 458470484..000000000 --- a/services/settings/pkg/config/log.go +++ /dev/null @@ -1,9 +0,0 @@ -package config - -// Log defines the available log configuration. -type Log struct { - Level string `mapstructure:"level" env:"OC_LOG_LEVEL;SETTINGS_LOG_LEVEL" desc:"The log level. Valid values are: 'panic', 'fatal', 'error', 'warn', 'info', 'debug', 'trace'." introductionVersion:"1.0.0"` - Pretty bool `mapstructure:"pretty" env:"OC_LOG_PRETTY;SETTINGS_LOG_PRETTY" desc:"Activates pretty log output." introductionVersion:"1.0.0"` - Color bool `mapstructure:"color" env:"OC_LOG_COLOR;SETTINGS_LOG_COLOR" desc:"Activates colorized log output." introductionVersion:"1.0.0"` - File string `mapstructure:"file" env:"OC_LOG_FILE;SETTINGS_LOG_FILE" desc:"The path to the log file. Activates logging to this file if set." introductionVersion:"1.0.0"` -} diff --git a/services/settings/pkg/logging/logging.go b/services/settings/pkg/logging/logging.go deleted file mode 100644 index 0bb0210bf..000000000 --- a/services/settings/pkg/logging/logging.go +++ /dev/null @@ -1,17 +0,0 @@ -package logging - -import ( - "github.com/opencloud-eu/opencloud/pkg/log" - "github.com/opencloud-eu/opencloud/services/settings/pkg/config" -) - -// Configure initializes a service-specific logger instance. -func Configure(name string, cfg *config.Log) log.Logger { - return log.NewLogger( - log.Name(name), - log.Level(cfg.Level), - log.Pretty(cfg.Pretty), - log.Color(cfg.Color), - log.File(cfg.File), - ) -} diff --git a/services/settings/pkg/store/metadata/store.go b/services/settings/pkg/store/metadata/store.go index b5684b377..c15b32702 100644 --- a/services/settings/pkg/store/metadata/store.go +++ b/services/settings/pkg/store/metadata/store.go @@ -74,14 +74,9 @@ func (s *Store) Init() { // New creates a new store func New(cfg *config.Config) settings.Manager { s := Store{ - Logger: olog.NewLogger( - olog.Color(cfg.Log.Color), - olog.Pretty(cfg.Log.Pretty), - olog.Level(cfg.Log.Level), - olog.File(cfg.Log.File), - ), - cfg: cfg, - l: &sync.Mutex{}, + Logger: olog.Configure(cfg.Service.Name, cfg.Commons, cfg.LogLevel), + cfg: cfg, + l: &sync.Mutex{}, } return &s