Open chuan137 opened 1 year ago
you can change /etc/localtime in the system directory.
You can use a custom formatter for timestamps with ConsoleWriter
.
cw := zerolog.NewConsoleWriter(func(w *zerolog.ConsoleWriter) {
w.FormatTimestamp = func(i interface{}) string {
if v, ok := i.(string); ok {
if ts, err := time.ParseInLocation(time.RFC3339, v, time.Local); err == nil {
return ts.UTC().Format(time.RFC3339)
}
}
return "<nil>"
}
})
log.Logger = log.Output(cw)
This was adapted from consoleDefaultFormatTimestamp
in console.go
. Link. Use that as a reference and make modifications wherever required.
I have assumed that you're using ConsoleWriter
only in development.
I tried to set the TimestampFunc, and it does change the json output, but not working on the console writer
and here is my logs looks like, they are printed from same run with different logger. The timestamp jumps by 1hr because I am in the +1 timezone. The timestamp in json is correct UTC time, but the console writer logs the local time. How can I make it also log the UTC time?