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() {
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))

View File

@ -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
}

View File

@ -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(