refactor: change NewLogger to use config manager, and have CM pass nil to newConfig

This commit is contained in:
Derrick Hammer 2024-02-27 03:54:00 -05:00
parent 8f8944a645
commit 6e3e096be9
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 8 additions and 7 deletions

View File

@ -24,9 +24,9 @@ import (
) )
func main() { func main() {
cfg, err := config.NewManager()
logger, logLevel := _logger.NewLogger() logger, logLevel := _logger.NewLogger(cfg)
cfg, err := config.NewManager(logger)
if err != nil { if err != nil {
logger.Fatal("Failed to load config", zap.Error(err)) logger.Fatal("Failed to load config", zap.Error(err))

View File

@ -28,8 +28,8 @@ type Manager struct {
changes bool changes bool
} }
func NewManager(logger *zap.Logger) (*Manager, error) { func NewManager() (*Manager, error) {
v, err := newConfig(logger) v, err := newConfig(nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -3,7 +3,8 @@ package logger
import ( import (
"os" "os"
"github.com/spf13/viper" "git.lumeweb.com/LumeWeb/portal/config"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
) )
@ -14,13 +15,13 @@ func NewFallbackLogger() *zap.Logger {
return logger return logger
} }
func NewLogger() (*zap.Logger, *zap.AtomicLevel) { func NewLogger(cm *config.Manager) (*zap.Logger, *zap.AtomicLevel) {
// Create a new atomic level // Create a new atomic level
atomicLevel := zap.NewAtomicLevel() atomicLevel := zap.NewAtomicLevel()
// Set initial log level, for example, info level // 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 // Create the logger with the atomic level
logger := zap.New(zapcore.NewCore( logger := zap.New(zapcore.NewCore(