Files
Erupe/utils/logger/logger.go
2024-10-11 00:15:11 +01:00

28 lines
626 B
Go

package logger
import (
"sync"
"go.uber.org/zap"
)
var (
instance Logger // Global instance of Logger interface
once sync.Once // Ensures logger is initialized only once
)
// Init initializes the global logger. This function should be called once, ideally during the app startup.
func Init(zapLogger *zap.Logger) {
once.Do(func() {
instance = NewZapLogger(zapLogger) // Assign the zapLogger as the global logger
})
}
// Get returns the global logger instance.
func Get() Logger {
if instance == nil {
panic("Logger is not initialized. Call logger.Init() before using the logger.")
}
return instance
}