From 7f8023ca8939c5c35be1b7821e497e227c106f08 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Thu, 8 Jan 2026 13:27:37 +0100 Subject: [PATCH] consolidate log config in sse Signed-off-by: Christian Richter --- services/sse/pkg/command/health.go | 8 +------- services/sse/pkg/command/server.go | 8 +------- services/sse/pkg/config/config.go | 15 +++------------ services/sse/pkg/config/defaults/defaultconfig.go | 12 ++---------- 4 files changed, 7 insertions(+), 36 deletions(-) diff --git a/services/sse/pkg/command/health.go b/services/sse/pkg/command/health.go index 0eafc3e40..82d9444bc 100644 --- a/services/sse/pkg/command/health.go +++ b/services/sse/pkg/command/health.go @@ -21,13 +21,7 @@ func Health(cfg *config.Config) *cobra.Command { return configlog.ReturnError(parser.ParseConfig(cfg)) }, RunE: func(cmd *cobra.Command, args []string) error { - logger := log.NewLogger( - log.Name(cfg.Service.Name), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) + logger := log.Configure(cfg.Service.Name, cfg.Commons, cfg.LogLevel) resp, err := http.Get( fmt.Sprintf( diff --git a/services/sse/pkg/command/server.go b/services/sse/pkg/command/server.go index feef04961..1dd0705f3 100644 --- a/services/sse/pkg/command/server.go +++ b/services/sse/pkg/command/server.go @@ -41,13 +41,7 @@ func Server(cfg *config.Config) *cobra.Command { } ctx := cfg.Context - logger := log.NewLogger( - log.Name(cfg.Service.Name), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) + logger := log.Configure(cfg.Service.Name, cfg.Commons, cfg.LogLevel) tracerProvider, err := tracing.GetTraceProvider(cmd.Context(), cfg.Commons.TracesExporter, cfg.Service.Name) if err != nil { diff --git a/services/sse/pkg/config/config.go b/services/sse/pkg/config/config.go index a2948f588..0f7c46694 100644 --- a/services/sse/pkg/config/config.go +++ b/services/sse/pkg/config/config.go @@ -9,10 +9,9 @@ import ( // Config combines all available configuration parts. type Config struct { - Commons *shared.Commons `yaml:"-"` // don't use this directly as configuration for a service - Log *Log - - Debug Debug `mask:"struct" yaml:"debug"` + Commons *shared.Commons `yaml:"-"` // don't use this directly as configuration for a service + LogLevel string `yaml:"loglevel" env:"OC_LOG_LEVEL;SSE_LOG_LEVEL" desc:"The log level. Valid values are: 'panic', 'fatal', 'error', 'warn', 'info', 'debug', 'trace'." introductionVersion:"1.0.0"` + Debug Debug `mask:"struct" yaml:"debug"` Service Service `yaml:"-"` KeepAliveInterval time.Duration `yaml:"keepalive_interval" env:"SSE_KEEPALIVE_INTERVAL" desc:"To prevent intermediate proxies from closing the SSE connection, send periodic SSE comments to keep it open." introductionVersion:"1.0.0"` @@ -29,14 +28,6 @@ type Service struct { Name string `yaml:"-"` } -// Log defines the available log configuration. -type Log struct { - Level string `mapstructure:"level" env:"OC_LOG_LEVEL;SSE_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;SSE_LOG_PRETTY" desc:"Activates pretty log output." introductionVersion:"1.0.0"` - Color bool `mapstructure:"color" env:"OC_LOG_COLOR;SSE_LOG_COLOR" desc:"Activates colorized log output." introductionVersion:"1.0.0"` - File string `mapstructure:"file" env:"OC_LOG_FILE;SSE_LOG_FILE" desc:"The path to the log file. Activates logging to this file if set." introductionVersion:"1.0.0"` -} - // Debug defines the available debug configuration. type Debug struct { Addr string `yaml:"addr" env:"SSE_DEBUG_ADDR" desc:"Bind address of the debug server, where metrics, health, config and debug endpoints will be exposed." introductionVersion:"1.0.0"` diff --git a/services/sse/pkg/config/defaults/defaultconfig.go b/services/sse/pkg/config/defaults/defaultconfig.go index 8ea79910f..30e2854ef 100644 --- a/services/sse/pkg/config/defaults/defaultconfig.go +++ b/services/sse/pkg/config/defaults/defaultconfig.go @@ -44,16 +44,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 {