mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-14 16:04:38 +01:00
28 lines
626 B
Go
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
|
|
}
|