consolidate log config in invitations

Signed-off-by: Christian Richter <c.richter@opencloud.eu>
This commit is contained in:
Christian Richter
2026-01-08 13:00:02 +01:00
parent 7f5a442750
commit e0d126da5c
6 changed files with 8 additions and 42 deletions
+2 -2
View File
@@ -5,9 +5,9 @@ import (
"net/http" "net/http"
"github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/config/configlog"
"github.com/opencloud-eu/opencloud/pkg/log"
"github.com/opencloud-eu/opencloud/services/invitations/pkg/config" "github.com/opencloud-eu/opencloud/services/invitations/pkg/config"
"github.com/opencloud-eu/opencloud/services/invitations/pkg/config/parser" "github.com/opencloud-eu/opencloud/services/invitations/pkg/config/parser"
"github.com/opencloud-eu/opencloud/services/invitations/pkg/logging"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@@ -21,7 +21,7 @@ func Health(cfg *config.Config) *cobra.Command {
return configlog.ReturnError(parser.ParseConfig(cfg)) return configlog.ReturnError(parser.ParseConfig(cfg))
}, },
RunE: func(cmd *cobra.Command, args []string) error { 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( resp, err := http.Get(
fmt.Sprintf( fmt.Sprintf(
+2 -2
View File
@@ -6,12 +6,12 @@ import (
"os/signal" "os/signal"
"github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/config/configlog"
"github.com/opencloud-eu/opencloud/pkg/log"
"github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/runner"
"github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/tracing"
"github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/pkg/version"
"github.com/opencloud-eu/opencloud/services/invitations/pkg/config" "github.com/opencloud-eu/opencloud/services/invitations/pkg/config"
"github.com/opencloud-eu/opencloud/services/invitations/pkg/config/parser" "github.com/opencloud-eu/opencloud/services/invitations/pkg/config/parser"
"github.com/opencloud-eu/opencloud/services/invitations/pkg/logging"
"github.com/opencloud-eu/opencloud/services/invitations/pkg/metrics" "github.com/opencloud-eu/opencloud/services/invitations/pkg/metrics"
"github.com/opencloud-eu/opencloud/services/invitations/pkg/server/debug" "github.com/opencloud-eu/opencloud/services/invitations/pkg/server/debug"
"github.com/opencloud-eu/opencloud/services/invitations/pkg/server/http" "github.com/opencloud-eu/opencloud/services/invitations/pkg/server/http"
@@ -29,7 +29,7 @@ func Server(cfg *config.Config) *cobra.Command {
return configlog.ReturnFatal(parser.ParseConfig(cfg)) return configlog.ReturnFatal(parser.ParseConfig(cfg))
}, },
RunE: func(cmd *cobra.Command, args []string) error { 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) traceProvider, err := tracing.GetTraceProvider(cmd.Context(), cfg.Commons.TracesExporter, cfg.Service.Name)
if err != nil { if err != nil {
return err return err
+2 -2
View File
@@ -12,8 +12,8 @@ type Config struct {
Service Service `yaml:"-"` Service Service `yaml:"-"`
Log *Log `yaml:"log"` LogLevel string `mapstructure:"level" env:"OC_LOG_LEVEL;INVITATIONS_LOG_LEVEL" desc:"The log level. Valid values are: 'panic', 'fatal', 'error', 'warn', 'info', 'debug', 'trace'." introductionVersion:"1.0.0"`
Debug Debug `yaml:"debug"` Debug Debug `yaml:"debug"`
HTTP HTTP `yaml:"http"` HTTP HTTP `yaml:"http"`
@@ -43,16 +43,8 @@ func DefaultConfig() *config.Config {
} }
func EnsureDefaults(cfg *config.Config) { func EnsureDefaults(cfg *config.Config) {
// provide with defaults for shared logging, since we need a valid destination address for "envdecode". if cfg.LogLevel == "" {
if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { cfg.LogLevel = "error"
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.Commons != nil { if cfg.Commons != nil {
-9
View File
@@ -1,9 +0,0 @@
package config
// Log defines the available log configuration.
type Log struct {
Level string `mapstructure:"level" env:"OC_LOG_LEVEL;INVITATIONS_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;INVITATIONS_LOG_PRETTY" desc:"Activates pretty log output." introductionVersion:"1.0.0"`
Color bool `mapstructure:"color" env:"OC_LOG_COLOR;INVITATIONS_LOG_COLOR" desc:"Activates colorized log output." introductionVersion:"1.0.0"`
File string `mapstructure:"file" env:"OC_LOG_FILE;INVITATIONS_LOG_FILE" desc:"The path to the log file. Activates logging to this file if set." introductionVersion:"1.0.0"`
}
@@ -1,17 +0,0 @@
package logging
import (
"github.com/opencloud-eu/opencloud/pkg/log"
"github.com/opencloud-eu/opencloud/services/invitations/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),
)
}