Closed 1xtr closed 5 months ago
I'd need more context.
Here is logger.go
package utils
import (
"os"
"strings"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
var Logger zerolog.Logger
func init() {
// Get log level from environment variable
logLevelStr := strings.ToLower(os.Getenv("LOG_LEVEL"))
// Default log level if not provided or invalid
logLevel := zerolog.InfoLevel
if logLevelStr != "" {
switch logLevelStr {
case "debug":
logLevel = zerolog.DebugLevel
case "info":
logLevel = zerolog.InfoLevel
case "warn":
logLevel = zerolog.WarnLevel
case "error":
logLevel = zerolog.ErrorLevel
case "fatal":
logLevel = zerolog.FatalLevel
case "panic":
logLevel = zerolog.PanicLevel
}
}
// UNIX Time is faster and smaller than most timestamps
zerolog.TimeFieldFormat = zerolog.TimeFormatUnixMs
zerolog.TimestampFieldName = "timestamp"
// Default level for this example is info, unless debug flag is present
zerolog.SetGlobalLevel(logLevel)
Logger = log.With().Caller().Logger()
}
func AddRequestIdToLogger(requestID string) {
Logger = log.With().Caller().Str("requestID", requestID).Logger()
}
Can't repro: https://play.golang.com/p/vnNPVLcP9F0
Project run on Docker with log driver fluentd
in fluent-bit I see error parsing json because it's not text
I'm not sure how that would impact the serialization.
@rs I cleared the Fluent config from comments. and after stack recreating everything works.
miracle =)
Why zerolog put logs to Stderr as bytes?
component:[109 97 105 110] level:[100 101 98 117 103] log:[] requestID:[117 110 107 110 111 119 110]]