How to set timezone when using ConsoleWriter?
Author: chuan137Created Feb 10, 2023Updated Sep 5, 2026
I tried to set the TimestampFunc, and it does change the json output, but not working on the console writer
zerolog.TimestampFunc = func() time.Time {
return time.Now().UTC()
}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?
{"level":"info","time":"2023-02-10T23:03:52Z","message":"config and template dir: ./"}
{"level":"info","time":"2023-02-10T23:03:52Z","message":"observe metrics from http://localhost:9090"}
2023-02-11T00:03:52+01:00 DBG pkg/netappsd/queue.go:67 > queue readiness = falseSource: rs/zerolog