From 2229fb36f59d872a27aa907415aa2d624c21787e Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Thu, 8 Jan 2026 11:19:41 +0100 Subject: [PATCH] consolidate log config in antivirus Signed-off-by: Christian Richter --- services/antivirus/pkg/command/health.go | 8 +------- services/antivirus/pkg/command/server.go | 9 +-------- services/antivirus/pkg/config/config.go | 14 +++----------- .../antivirus/pkg/config/defaults/defaultconfig.go | 4 ++-- 4 files changed, 7 insertions(+), 28 deletions(-) diff --git a/services/antivirus/pkg/command/health.go b/services/antivirus/pkg/command/health.go index 937f7b2df..a3c5df8de 100644 --- a/services/antivirus/pkg/command/health.go +++ b/services/antivirus/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/antivirus/pkg/command/server.go b/services/antivirus/pkg/command/server.go index dd6aa6e22..283bbd093 100644 --- a/services/antivirus/pkg/command/server.go +++ b/services/antivirus/pkg/command/server.go @@ -32,14 +32,7 @@ func Server(cfg *config.Config) *cobra.Command { defer cancel() } 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) traceProvider, err := tracing.GetTraceProvider(cmd.Context(), cfg.Commons.TracesExporter, cfg.Service.Name) if err != nil { diff --git a/services/antivirus/pkg/config/config.go b/services/antivirus/pkg/config/config.go index c0a25c090..5e7266b5d 100644 --- a/services/antivirus/pkg/config/config.go +++ b/services/antivirus/pkg/config/config.go @@ -29,9 +29,9 @@ const ( // Config combines all available configuration parts. type Config struct { - Commons *shared.Commons `yaml:"-"` // don't use this directly as configuration for a service - File string - Log *Log + Commons *shared.Commons `yaml:"-"` // don't use this directly as configuration for a service + File string + LogLevel string `mapstructure:"level" env:"OC_LOG_LEVEL;ANTIVIRUS_LOG_LEVEL" desc:"The log level. Valid values are: 'panic', 'fatal', 'error', 'warn', 'info', 'debug', 'trace'." introductionVersion:"1.0.0"` Debug Debug `yaml:"debug" mask:"struct"` @@ -55,14 +55,6 @@ type Service struct { Name string `yaml:"-"` } -// Log defines the available log configuration. -type Log struct { - Level string `mapstructure:"level" env:"OC_LOG_LEVEL;ANTIVIRUS_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;ANTIVIRUS_LOG_PRETTY" desc:"Activates pretty log output." introductionVersion:"1.0.0"` - Color bool `mapstructure:"color" env:"OC_LOG_COLOR;ANTIVIRUS_LOG_COLOR" desc:"Activates colorized log output." introductionVersion:"1.0.0"` - File string `mapstructure:"file" env:"OC_LOG_FILE;ANTIVIRUS_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:"ANTIVIRUS_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/antivirus/pkg/config/defaults/defaultconfig.go b/services/antivirus/pkg/config/defaults/defaultconfig.go index 446e7c215..7b912d588 100644 --- a/services/antivirus/pkg/config/defaults/defaultconfig.go +++ b/services/antivirus/pkg/config/defaults/defaultconfig.go @@ -51,8 +51,8 @@ func DefaultConfig() *config.Config { // EnsureDefaults adds default values to the configuration if they are not set yet func EnsureDefaults(cfg *config.Config) { - if cfg.Log == nil { - cfg.Log = &config.Log{} + if cfg.LogLevel == "" { + cfg.LogLevel = "error" } }