From d0f27631c052ab1aee2b19bf37951d9fe4d3890d Mon Sep 17 00:00:00 2001 From: beorn7 Date: Thu, 5 Dec 2024 16:31:21 +0100 Subject: [PATCH] Revert "fix(promslog): always use UTC for time (#735)" This reverts commit 145b50adb4ece06ea09a5b0abcbedb76bd1b123a. See discussion on Slack. We should first decide which log format we want before changing it from what is already released in prometheus/prometheus. --- promslog/slog.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/promslog/slog.go b/promslog/slog.go index 6e8fbabc..a70eb6a4 100644 --- a/promslog/slog.go +++ b/promslog/slog.go @@ -68,16 +68,13 @@ var ( return a } - defaultReplaceAttrFunc = func(groups []string, a slog.Attr) slog.Attr { - key := a.Key - switch key { - case slog.TimeKey: - t := a.Value.Time() - a.Value = slog.TimeValue(t.UTC()) - case slog.SourceKey: - src, _ := a.Value.Any().(*slog.Source) + truncateSourceAttrFunc = func(groups []string, a slog.Attr) slog.Attr { + if a.Key != slog.SourceKey { + return a + } + + if src, ok := a.Value.Any().(*slog.Source); ok { a.Value = slog.StringValue(filepath.Base(src.File) + ":" + strconv.Itoa(src.Line)) - default: } return a @@ -181,7 +178,7 @@ func New(config *Config) *slog.Logger { logHandlerOpts := &slog.HandlerOptions{ Level: config.Level.lvl, AddSource: true, - ReplaceAttr: defaultReplaceAttrFunc, + ReplaceAttr: truncateSourceAttrFunc, } if config.Style == GoKitStyle {