Add console flag for logging initialization

This commit is contained in:
Søren Rasmussen 2022-04-06 07:55:21 +02:00
parent 037bdbebcc
commit f0b69c4dc8

View file

@ -4,26 +4,18 @@ import (
"os"
"time"
"github.com/getsentry/sentry-go"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
var levelsMapping = map[zerolog.Level]sentry.Level{
zerolog.DebugLevel: sentry.LevelDebug,
zerolog.InfoLevel: sentry.LevelInfo,
zerolog.WarnLevel: sentry.LevelWarning,
zerolog.ErrorLevel: sentry.LevelError,
zerolog.FatalLevel: sentry.LevelFatal,
zerolog.PanicLevel: sentry.LevelFatal,
}
// Initialize configures ZeroLog with defaults.
func Initialize() {
func Initialize(console bool) {
if console {
cw := zerolog.NewConsoleWriter()
cw.Out = os.Stderr
cw.TimeFormat = "15:04:05"
log.Logger = zerolog.New(cw).With().Timestamp().Logger()
}
zerolog.DurationFieldUnit = time.Millisecond
}