main.go.
log.Info().Msgf(“%v”, clientName) – to write messages about initializing programs/clients
…
api request starts a few goroutines – each routine has following
log.Debug() or log.Msgf()
defer func(start time.Time) {
var e *zerolog.Event
switch {
case err != nil:
e = log.Error()
default:
e = log.WithLevel(v.Config.Level())
}
e.
Str(“message”, message).
e.AnErr(constants.Err, err).Send()
}(time.Now())
Your code formatting above makes it slightly hard to read. If you can create a reproducible example in the go playground, you could try opening an issue in the github repo of the library you’re trying to use.
I checked the ZeroLog source. It has a single global json formatter and does not synchronize access to the formatter. Multiple goroutines calling ZeroLog functions that require the json formatter can cause the json formatter’s state to become corrupt.