Skip to content

Commit 31ee791

Browse files
committed
promslog: Use the default timezone (again)
As per the dev-summit discussion, we want to use the default timezone as selected by slog after all rather than a hardcoded UTC. (This was accidentally introduced earlier when moving from gokit to slog, but then switched back to hardcoded UTC in PR #735.) Environments that have configured UTC anyway won't see any difference, but those with other timezones configured will see the configured timezone for the timestamps in their logs. This is in line with how slog behaves by default. Example timestamp _before_ this change and also _after_ this change with UTC configured in the environment via a suitable way (e.g. setting `TZ=UTC` on Linux): time=2025-04-10T12:00:38.179Z Example timestamp _after_ this change with location Europe/Berlin, i.e. timezone is CET or CEST: time=2025-04-10T14:00:03.120+02:00 Note that the precise delta to UTC is in the timestamp. So this change will also be transparent to the usual logs processing tools. Signed-off-by: beorn7 <[email protected]>
1 parent 318ef65 commit 31ee791

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

promslog/slog.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,8 @@ func defaultReplaceAttr(_ []string, a slog.Attr) slog.Attr {
200200
key := a.Key
201201
switch key {
202202
case slog.TimeKey:
203-
if t, ok := a.Value.Any().(time.Time); ok {
204-
a.Value = slog.TimeValue(t.UTC())
205-
} else {
203+
// Note that we do not change the timezone to UTC anymore.
204+
if _, ok := a.Value.Any().(time.Time); !ok {
206205
// If we can't cast the any from the value to a
207206
// time.Time, it means the caller logged
208207
// another attribute with a key of `time`.

0 commit comments

Comments
 (0)