Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.

Use ISO 8601 timestamp format in JSON to Loggly #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

wbrady
Copy link

@wbrady wbrady commented Apr 13, 2015

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

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
@travisjeffery
Copy link

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)

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

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.

Copy link
Author

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.
@wbrady
Copy link
Author

wbrady commented Apr 22, 2015

Any other comments?

@arp242
Copy link

arp242 commented Sep 14, 2016

Any other comments?

Yes; merge it! Right now logs appear to be coming from 45,000 years in the future ;-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants