refactor: logger does not need to be a singleton
This commit is contained in:
parent
eae3de419c
commit
8ceb8c1eb9
|
@ -123,7 +123,7 @@ func (p *PortalImpl) getInitFuncs() []func() error {
|
|||
},
|
||||
|
||||
func() error {
|
||||
p.logger = logger.Get(p.Config())
|
||||
p.logger = logger.Init(p.Config())
|
||||
|
||||
return nil
|
||||
},
|
||||
|
|
|
@ -7,26 +7,20 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
logger *zap.Logger
|
||||
)
|
||||
func Init(viper *viper.Viper) *zap.Logger {
|
||||
|
||||
func Get(viper *viper.Viper) *zap.Logger {
|
||||
if logger == nil {
|
||||
// Create a new atomic level
|
||||
atomicLevel := zap.NewAtomicLevel()
|
||||
|
||||
// Create a new atomic level
|
||||
atomicLevel := zap.NewAtomicLevel()
|
||||
// Set initial log level, for example, info level
|
||||
atomicLevel.SetLevel(mapLogLevel(viper.GetString("core.log.level")))
|
||||
|
||||
// Set initial log level, for example, info level
|
||||
atomicLevel.SetLevel(mapLogLevel(viper.GetString("core.log.level")))
|
||||
|
||||
// Create the logger with the atomic level
|
||||
logger = zap.New(zapcore.NewCore(
|
||||
zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig()),
|
||||
zapcore.Lock(os.Stdout),
|
||||
atomicLevel,
|
||||
))
|
||||
}
|
||||
// Create the logger with the atomic level
|
||||
logger := zap.New(zapcore.NewCore(
|
||||
zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig()),
|
||||
zapcore.Lock(os.Stdout),
|
||||
atomicLevel,
|
||||
))
|
||||
|
||||
return logger
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue