-
Notifications
You must be signed in to change notification settings - Fork 29
Use ISO 8601 timestamp format in JSON to Loggly #8
base: master
Are you sure you want to change the base?
Conversation
The Loggly documentation states that the timestamp field must be in ISO 8601 format for Loggly to recognize it. This way the actual time displayed in Loggly will be based on the value sent. Currently when sending the UNIX time, Loggly will not recognize it and will display the time it received the message instead. https://www.loggly.com/docs/automated-parsing/#json
thanks for the pr! lgtm |
@@ -92,7 +92,7 @@ func New(token string, tags ...string) *Client { | |||
// Send buffers `msg` for async sending. | |||
func (c *Client) Send(msg Message) error { | |||
if _, exists := msg["timestamp"]; !exists { | |||
msg["timestamp"] = time.Now().UnixNano() / int64(time.Millisecond) | |||
msg["timestamp"] = time.Now().UTC().Format(time.RFC3339) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
time.Time
is marshalled with RFC3339 by default. I would leave out formatting here and simply set msg["timestamp"]
to a time.Time
value. See http://golang.org/pkg/time/#Time.MarshalJSON
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it is required to drop the timezone information and only send UTC times. The timezone can be interesting information to have in the logs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default format is RFC3339 with 9 digits of fractional second time (the RFC3339Nano format). The Loggly spec only supports 6 digits of fractional second time. I checked it myself and it only works with 6 digits.
I've added a commit to remove the UTC conversion and use a custom format string to match the supported format.
The RFC3339Nano format includes 9 digits of sub-second time. The Loggly spec only supports 6. Therefore I’m using a custom format string.
Any other comments? |
Yes; merge it! Right now logs appear to be coming from 45,000 years in the future ;-) |
The Loggly documentation states that the timestamp field must be in ISO 8601 format for Loggly to recognize it. This way the actual time displayed in Loggly will be based on the value sent. Currently when sending the UNIX time, Loggly will not recognize it and will display the time it received the message instead.
https://www.loggly.com/docs/automated-parsing/#json