2021-12-01 19:22:07 +00:00
|
|
|
package logging
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Initialize configures ZeroLog with defaults.
|
2022-04-06 05:55:21 +00:00
|
|
|
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()
|
|
|
|
}
|
2021-12-01 19:22:07 +00:00
|
|
|
|
|
|
|
zerolog.DurationFieldUnit = time.Millisecond
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetGlobalLevel sets the global log level according to the passed debug flag.
|
|
|
|
func SetGlobalLevel(debug bool) {
|
|
|
|
if debug {
|
|
|
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
|
|
|
} else {
|
|
|
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
|
|
|
}
|
|
|
|
}
|