refactor: change NewLogger to use config manager, and have CM pass nil to newConfig
This commit is contained in:
parent
8f8944a645
commit
6e3e096be9
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue