Skip to content

Commit 5041b59

Browse files
authored
Set default logstash formatter timestamp to RFC3339Nano (#73)
Signed-off-by: Boaz Shuster <[email protected]>
1 parent 8a91b84 commit 5041b59

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

hook.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"io"
66
"sync"
7+
"time"
78

89
"github.com/sirupsen/logrus"
910
)
@@ -13,7 +14,6 @@ import (
1314
// formatter to format the entry to a Logstash format before sending.
1415
//
1516
// To initialize it use the `New` function.
16-
//
1717
type Hook struct {
1818
writer io.Writer
1919
formatter logrus.Formatter
@@ -117,8 +117,11 @@ func DefaultFormatter(fields logrus.Fields) logrus.Formatter {
117117
}
118118

119119
return LogstashFormatter{
120-
Formatter: &logrus.JSONFormatter{FieldMap: logstashFieldMap},
121-
Fields: fields,
120+
Formatter: &logrus.JSONFormatter{
121+
FieldMap: logstashFieldMap,
122+
TimestampFormat: time.RFC3339Nano,
123+
},
124+
Fields: fields,
122125
}
123126
}
124127

hook_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func TestDefaultFormatterWithEmptyFields(t *testing.T) {
125125
"\"Key1\":\"Value1\"",
126126
"\"@version\":\"1\"",
127127
"\"type\":\"log\"",
128-
fmt.Sprintf("\"@timestamp\":\"%s\"", now.Format(time.RFC3339)),
128+
fmt.Sprintf("\"@timestamp\":\"%s\"", now.Format(time.RFC3339Nano)),
129129
}
130130

131131
for _, exp := range expected {

0 commit comments

Comments
 (0)