2021-01-10 18:16:20 +00:00
|
|
|
// Package logger wraps an external logging package
|
|
|
|
package logger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"go.uber.org/zap/zapcore"
|
|
|
|
)
|
|
|
|
|
|
|
|
type logger = zap.SugaredLogger
|
|
|
|
|
|
|
|
// DebugLevel is exported (5)
|
|
|
|
var DebugLevel = zapcore.DebugLevel
|
|
|
|
|
|
|
|
// InfoLevel is exported (4)
|
|
|
|
var InfoLevel = zapcore.InfoLevel
|
|
|
|
|
|
|
|
// WarnLevel is exported (3)
|
|
|
|
var WarnLevel = zapcore.WarnLevel
|
|
|
|
|
|
|
|
// ErrorLevel is exported (2)
|
|
|
|
var ErrorLevel = zapcore.ErrorLevel
|
|
|
|
|
|
|
|
// PanicLevel is exported (1)
|
|
|
|
var PanicLevel = zapcore.PanicLevel
|
|
|
|
|
|
|
|
// New creates a new logger and returns it
|
|
|
|
func New(level zapcore.Level) *logger {
|
|
|
|
var theLogger *zap.Logger
|
|
|
|
var err error
|
|
|
|
if level == zapcore.DebugLevel {
|
|
|
|
theLogger, err = zap.NewDevelopment()
|
|
|
|
} else {
|
|
|
|
theLogger, err = zap.NewProduction()
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("logger.New: 💣 ⛔ zap logger init fail")
|
|
|
|
}
|
|
|
|
// theLogger.SetLevel
|
2021-01-27 21:17:16 +00:00
|
|
|
defer theLogger.Sync() //nolint:errcheck // it's defered
|
2021-01-10 18:16:20 +00:00
|
|
|
return theLogger.Sugar()
|
|
|
|
}
|