lib/app/logger/logger.go

44 lines
933 B
Go
Raw Permalink Normal View History

2021-08-05 19:55:24 +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
defer theLogger.Sync() //nolint:errcheck // it's defered
return theLogger.Sugar()
}