From 587e3c76ff0c649e47470cbe13aaadb8391a52dc Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Thu, 8 Jan 2026 11:50:54 +0100 Subject: [PATCH] consolidate log config in audit Signed-off-by: Christian Richter --- services/audit/pkg/command/server.go | 5 ++--- services/audit/pkg/config/config.go | 10 ++++------ .../audit/pkg/config/defaults/defaultconfig.go | 12 ++---------- services/audit/pkg/config/log.go | 9 --------- services/audit/pkg/logging/logging.go | 17 ----------------- 5 files changed, 8 insertions(+), 45 deletions(-) delete mode 100644 services/audit/pkg/config/log.go delete mode 100644 services/audit/pkg/logging/logging.go diff --git a/services/audit/pkg/command/server.go b/services/audit/pkg/command/server.go index 4ce05241da..3ebc610441 100644 --- a/services/audit/pkg/command/server.go +++ b/services/audit/pkg/command/server.go @@ -7,10 +7,10 @@ import ( "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/generators" + "github.com/opencloud-eu/opencloud/pkg/log" "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/services/audit/pkg/config" "github.com/opencloud-eu/opencloud/services/audit/pkg/config/parser" - "github.com/opencloud-eu/opencloud/services/audit/pkg/logging" "github.com/opencloud-eu/opencloud/services/audit/pkg/server/debug" svc "github.com/opencloud-eu/opencloud/services/audit/pkg/service" "github.com/opencloud-eu/opencloud/services/audit/pkg/types" @@ -35,8 +35,7 @@ func Server(cfg *config.Config) *cobra.Command { defer cancel() } ctx := cfg.Context - - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := log.Configure(cfg.Service.Name, cfg.Commons, cfg.LogLevel) gr := runner.NewGroup() connName := generators.GenerateConnectionName(cfg.Service.Name, generators.NTypeBus) diff --git a/services/audit/pkg/config/config.go b/services/audit/pkg/config/config.go index c98fd9f215..37c5f9b6c0 100644 --- a/services/audit/pkg/config/config.go +++ b/services/audit/pkg/config/config.go @@ -8,12 +8,10 @@ import ( // Config combines all available configuration parts. type Config struct { - Commons *shared.Commons `yaml:"-"` // don't use this directly as configuration for a service - - Service Service `yaml:"-"` - - Log *Log `yaml:"log"` - Debug Debug `yaml:"debug"` + Commons *shared.Commons `yaml:"-"` // don't use this directly as configuration for a service + Service Service `yaml:"-"` + LogLevel string `yaml:"level" env:"OC_LOG_LEVEL;AUDIT_LOG_LEVEL" desc:"The log level. Valid values are: 'panic', 'fatal', 'error', 'warn', 'info', 'debug', 'trace'." introductionVersion:"1.0.0"` + Debug Debug `yaml:"debug"` Events Events `yaml:"events"` Auditlog Auditlog `yaml:"auditlog"` diff --git a/services/audit/pkg/config/defaults/defaultconfig.go b/services/audit/pkg/config/defaults/defaultconfig.go index 20d8818928..0dbc9e5fd8 100644 --- a/services/audit/pkg/config/defaults/defaultconfig.go +++ b/services/audit/pkg/config/defaults/defaultconfig.go @@ -37,16 +37,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" } } diff --git a/services/audit/pkg/config/log.go b/services/audit/pkg/config/log.go deleted file mode 100644 index c9ffe7c970..0000000000 --- a/services/audit/pkg/config/log.go +++ /dev/null @@ -1,9 +0,0 @@ -package config - -// Log defines the available log configuration. -type Log struct { - Level string `yaml:"level" env:"OC_LOG_LEVEL;AUDIT_LOG_LEVEL" desc:"The log level. Valid values are: 'panic', 'fatal', 'error', 'warn', 'info', 'debug', 'trace'." introductionVersion:"1.0.0"` - Pretty bool `yaml:"pretty" env:"OC_LOG_PRETTY;AUDIT_LOG_PRETTY" desc:"Activates pretty log output." introductionVersion:"1.0.0"` - Color bool `yaml:"color" env:"OC_LOG_COLOR;AUDIT_LOG_COLOR" desc:"Activates colorized log output." introductionVersion:"1.0.0"` - File string `yaml:"file" env:"OC_LOG_FILE;AUDIT_LOG_FILE" desc:"The path to the log file. Activates logging to this file if set." introductionVersion:"1.0.0"` -} diff --git a/services/audit/pkg/logging/logging.go b/services/audit/pkg/logging/logging.go deleted file mode 100644 index 9387cf2c0d..0000000000 --- a/services/audit/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/audit/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), - ) -}