Skip to content

Commit 40a5d31

Browse files
authored
feat: Support ts as time field (#27)
1 parent aa8e0d3 commit 40a5d31

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

internal/pkg/source/entry_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ func TestParseLogEntry(t *testing.T) {
4444
assert.Equal(t, "1", logEntry.Time)
4545
},
4646
}, {
47+
Name: "ts_number",
48+
JSON: `{"ts":1}`,
49+
Assert: func(tb testing.TB, logEntry source.LogEntry) {
50+
tb.Helper()
51+
52+
assert.Equal(t, "1", logEntry.Time)
53+
},
54+
}, {
4755
Name: "time_text",
4856
JSON: `{"time":"1970-01-01T00:00:00.00"}`,
4957
Assert: func(tb testing.TB, logEntry source.LogEntry) {
@@ -60,6 +68,14 @@ func TestParseLogEntry(t *testing.T) {
6068
assert.Equal(t, "1970-01-01T00:00:00.00", logEntry.Time)
6169
},
6270
}, {
71+
Name: "ts_text",
72+
JSON: `{"ts":"1970-01-01T00:00:00.00"}`,
73+
Assert: func(tb testing.TB, logEntry source.LogEntry) {
74+
tb.Helper()
75+
76+
assert.Equal(t, "1970-01-01T00:00:00.00", logEntry.Time)
77+
},
78+
}, {
6379
Name: "message",
6480
JSON: `{"message":"message"}`,
6581
Assert: func(tb testing.TB, logEntry source.LogEntry) {

internal/pkg/source/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func extractTime(value *fastjson.Value) string {
11-
timeValue := extractValue(value, "timestamp", "time", "t")
11+
timeValue := extractValue(value, "timestamp", "time", "t", "ts")
1212
if timeValue != "" {
1313
return formatMessage(strings.TrimSpace(timeValue))
1414
}

0 commit comments

Comments
 (0)