Add console flag for logging initialization
This commit is contained in:
parent
037bdbebcc
commit
f0b69c4dc8
1 changed files with 7 additions and 15 deletions
|
@ -4,26 +4,18 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/getsentry/sentry-go"
|
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/rs/zerolog/log"
|
"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.
|
// Initialize configures ZeroLog with defaults.
|
||||||
func Initialize() {
|
func Initialize(console bool) {
|
||||||
cw := zerolog.NewConsoleWriter()
|
if console {
|
||||||
cw.Out = os.Stderr
|
cw := zerolog.NewConsoleWriter()
|
||||||
cw.TimeFormat = "15:04:05"
|
cw.Out = os.Stderr
|
||||||
log.Logger = zerolog.New(cw).With().Timestamp().Logger()
|
cw.TimeFormat = "15:04:05"
|
||||||
|
log.Logger = zerolog.New(cw).With().Timestamp().Logger()
|
||||||
|
}
|
||||||
|
|
||||||
zerolog.DurationFieldUnit = time.Millisecond
|
zerolog.DurationFieldUnit = time.Millisecond
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue