@@ -323,7 +323,7 @@ E0000 00:00:00.000000 00000 logs_test.go:000] "Contextual error" err="fake-err
323
323
var (
324
324
timestampRegexpStdLog = regexp .MustCompile (`\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}` )
325
325
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* ` )
327
327
fileAndLineRegexpJSON = regexp .MustCompile (`"caller":"([^"]+).go:\d+"` )
328
328
fileAndLineRegexpKlog = regexp .MustCompile (` ([^:]+).go:\d+` )
329
329
)
@@ -361,6 +361,16 @@ func Test_replaceWithStaticTimestamps(t *testing.T) {
361
361
input : `I1018 15:20:42.861239 2386 logs_test.go:13] "Contextual Info Level 3" logger="foo" key="value"` ,
362
362
expected : `I0000 00:00:00.000000 00000 logs_test.go:000] "Contextual Info Level 3" logger="foo" key="value"` ,
363
363
},
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
+ },
364
374
}
365
375
for _ , test := range tests {
366
376
t .Run (test .name , func (t * testing.T ) {
0 commit comments