44 lines
899 B
Go
44 lines
899 B
Go
|
// 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
|
||
|
defer theLogger.Sync()
|
||
|
return theLogger.Sugar()
|
||
|
}
|