Skip to content

Commit a41b832

Browse files
committed
logs_test.go: replaceWithStaticTimestamps: ts may not have nanoseconds
1 parent 6752d49 commit a41b832

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pkg/logs/logs_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ E0000 00:00:00.000000 00000 logs_test.go:000] "Contextual error" err="fake-err
323323
var (
324324
timestampRegexpStdLog = regexp.MustCompile(`\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}`)
325325
timestampRegexpKlog = regexp.MustCompile(`\d{4} \d{2}:\d{2}:\d{2}\.\d{6} +\d+`)
326-
timestampRegexpJSON = regexp.MustCompile(`"ts":\d+\.\d+`)
326+
timestampRegexpJSON = regexp.MustCompile(`"ts":\d+\.?\d*`)
327327
fileAndLineRegexpJSON = regexp.MustCompile(`"caller":"([^"]+).go:\d+"`)
328328
fileAndLineRegexpKlog = regexp.MustCompile(` ([^:]+).go:\d+`)
329329
)
@@ -361,6 +361,16 @@ func Test_replaceWithStaticTimestamps(t *testing.T) {
361361
input: `I1018 15:20:42.861239 2386 logs_test.go:13] "Contextual Info Level 3" logger="foo" key="value"`,
362362
expected: `I0000 00:00:00.000000 00000 logs_test.go:000] "Contextual Info Level 3" logger="foo" key="value"`,
363363
},
364+
{
365+
name: "json-with-nanoseconds",
366+
input: `{"ts":1729270111728.125,"caller":"logs/logs_test.go:000","msg":"slog Warn","v":0}`,
367+
expected: `{"ts":0000000000000.000,"caller":"logs/logs_test.go:000","msg":"slog Warn","v":0}`,
368+
},
369+
{
370+
name: "json-might-not-have-nanoseconds",
371+
input: `{"ts":1729270111728,"caller":"logs/logs_test.go:000","msg":"slog Info","v":0}`,
372+
expected: `{"ts":0000000000000.000,"caller":"logs/logs_test.go:000","msg":"slog Info","v":0}`,
373+
},
364374
}
365375
for _, test := range tests {
366376
t.Run(test.name, func(t *testing.T) {

0 commit comments

Comments
 (0)