2023-05-22 23:05:38 +00:00
|
|
|
package logger
|
|
|
|
|
|
|
|
import (
|
2023-06-06 20:37:22 +00:00
|
|
|
"github.com/spf13/viper"
|
2023-05-22 23:05:38 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
var logger *zap.Logger
|
|
|
|
|
|
|
|
func Init() {
|
2023-06-06 20:37:22 +00:00
|
|
|
var newLogger *zap.Logger
|
|
|
|
var err error
|
|
|
|
|
|
|
|
if viper.GetBool("debug") {
|
|
|
|
newLogger, err = zap.NewDevelopment()
|
|
|
|
} else {
|
|
|
|
newLogger, err = zap.NewProduction()
|
|
|
|
}
|
2023-05-22 23:05:38 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
logger = newLogger
|
|
|
|
}
|
|
|
|
|
|
|
|
func Get() *zap.Logger {
|
|
|
|
return logger
|
|
|
|
}
|