Skip to content

Commit 6fc9638

Browse files
committed
Use SYSLOG_TIMESTAMP instead of TIMESTAMP and format as micros
1 parent aab4f1b commit 6fc9638

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

journal.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ func (h *Handler) Handle(ctx context.Context, r slog.Record) error {
133133
// NOTE: journald does its own timestamping. Lets just ignore
134134
// NOTE: slogtest requires this. grrr
135135
if !r.Time.IsZero() {
136-
buf = h.appendKV(buf, "TIMESTAMP", []byte(strconv.Itoa(int(r.Time.Unix()))))
136+
timestampStr := strconv.FormatInt(r.Time.UnixMicro(), 10)
137+
buf = h.appendKV(buf, "SYSLOG_TIMESTAMP", []byte(timestampStr))
137138
}
138139

139140
buf = append(buf, h.preformatted...)

journal_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func TestBasicFunctionality(t *testing.T) {
111111
if err != nil {
112112
t.Fatal(err)
113113
}
114-
v, ok := kv["TIMESTAMP"]
114+
v, ok := kv["SYSLOG_TIMESTAMP"]
115115
if ok {
116116
t.Error("Unexpected timestamp", v, kv)
117117
}
@@ -216,7 +216,7 @@ func TestSlogtest(t *testing.T) {
216216
k = slog.MessageKey
217217
case "PRIORITY":
218218
k = slog.LevelKey
219-
case "TIMESTAMP":
219+
case "SYSLOG_TIMESTAMP":
220220
k = slog.TimeKey
221221
}
222222
m[k] = v

0 commit comments

Comments
 (0)