From 6e3e096be9913d91e3de92826cb3c0a1b13cf143 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 27 Feb 2024 03:54:00 -0500 Subject: [PATCH] refactor: change NewLogger to use config manager, and have CM pass nil to newConfig --- cmd/portal/main.go | 4 ++-- config/config.go | 4 ++-- logger/logger.go | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/portal/main.go b/cmd/portal/main.go index 3cd7961..a5e9dfb 100644 --- a/cmd/portal/main.go +++ b/cmd/portal/main.go @@ -24,9 +24,9 @@ import ( ) func main() { + cfg, err := config.NewManager() - logger, logLevel := _logger.NewLogger() - cfg, err := config.NewManager(logger) + logger, logLevel := _logger.NewLogger(cfg) if err != nil { logger.Fatal("Failed to load config", zap.Error(err)) diff --git a/config/config.go b/config/config.go index a4aea88..a776351 100644 --- a/config/config.go +++ b/config/config.go @@ -28,8 +28,8 @@ type Manager struct { changes bool } -func NewManager(logger *zap.Logger) (*Manager, error) { - v, err := newConfig(logger) +func NewManager() (*Manager, error) { + v, err := newConfig(nil) if err != nil { return nil, err } diff --git a/logger/logger.go b/logger/logger.go index 4518f36..6bd668a 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -3,7 +3,8 @@ package logger import ( "os" - "github.com/spf13/viper" + "git.lumeweb.com/LumeWeb/portal/config" + "go.uber.org/zap" "go.uber.org/zap/zapcore" ) @@ -14,13 +15,13 @@ func NewFallbackLogger() *zap.Logger { return logger } -func NewLogger() (*zap.Logger, *zap.AtomicLevel) { +func NewLogger(cm *config.Manager) (*zap.Logger, *zap.AtomicLevel) { // Create a new atomic level atomicLevel := zap.NewAtomicLevel() // Set initial log level, for example, info level - atomicLevel.SetLevel(mapLogLevel(viper.GetString("core.log.level"))) + atomicLevel.SetLevel(mapLogLevel(cm.Config().Core.Log.Level)) // Create the logger with the atomic level logger := zap.New(zapcore.NewCore(