-
Notifications
You must be signed in to change notification settings - Fork 8
Add support for timestamp timezone locale #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@kz Accepting pull requests for your library? 😄 |
|
Hi @ewohltman - many thanks for your PR, and for the very detailed explanation. I definitely am accepting PRs. :) I'll take a look tomorrow and get back to you then! |
|
Real world usage of your library (well, the fork for this pull request) in the wild: https://github.com/ewohltman/ephemeral-roles/blob/master/pkg/logging/logging.go |
|
Glad to see that the library is being used in the wild! I'll leave a thorough review shortly. |
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.
@ewohltman - I've reviewed the code. discordrus.go looks good, however a few changes need to be made in README.md and discordrus_test.go. Thanks for your help so far!
Also, once you've implemented all changes, please can you squash your commits with the message Add support for timestamp timezone locale (#2)?
README.md
Outdated
| # discordrus | a [Discord](https://discordapp.com/) hook for [Logrus](https://github.com/Sirupsen/logrus) <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:"/> [](https://travis-ci.org/kz/discordrus) [](https://godoc.org/github.com/kz/discordrus) | ||
|
|
||
| **Current version:** v1.0.1 | ||
| **Current version:** v1.0.2 |
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.
Please can you change this to v1.1.0? Your commit has added new functionality, so semver dictates a minor version increase!
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.
✔
README.md
Outdated
| logrus.SetOutput(os.Stderr) | ||
| logrus.SetLevel(logrus.DebugLevel) | ||
|
|
||
| // Log timestamps in UTC |
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 don't think we'll need 37-55 as there should be a simpler way of approaching this (detailed below). Additionally, the example usage should be as straightforward as possible so most people can get an understanding of the API, so if there is additional usage to be documented, a ### H3 header could be used beneath the default usage.
If you want TimestampFormat to include the time zone at the end, could you test out your code using "Jan 2 15:04:05.00000 MST"? According to https://golang.org/pkg/time/#Time.String, MST would be replaced with the time zone during formatting, which would remove the need for L37-55 entirely.
Also, in general, if you do want to retrieve the time zone token, I believe there is a much simpler way of doing this using the Zone function. You can find a demonstration here: https://play.golang.org/p/OHKTfqqnwrR
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.
Great tip! Maybe there is something special about "MST"? I too saw that in other documentation, however at the time I was testing using "UTC" so maybe that wasn't being parsed how I expected? Explains why I would have to explicitly get the time zone string myself and append it to the pattern since it wasn't being replaced.
✔
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 had the same confusion around the same time I was writing discordrus. Basically, every token in the format (Jan, 2, 15, 04, 05, MST) actually have meanings behind them (month, date of month without trailing zero, hour, minute, seconds, time zone respectively). You'd think you could replace Jan with Feb, but this wouldn't work since the point of hardcoding the meanings to values is to prevent ambiguity (it wouldn't be very straightforward getting Go to parse 15:15:15000, for example).
The significance of the values chosen are explained well here:
README.md
Outdated
| DisableTimestamp: false, // Setting this to true will disable timestamps from appearing in the footer | ||
| TimestampFormat: "Jan 2 15:04:05.00000", // The timestamp takes this format; if it is unset, it will take logrus' default format | ||
| EnableCustomColors: true, // If set to true, the below CustomLevelColors will apply | ||
| Username: "", |
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.
Please be sure to keep the values from the old Opts.
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.
✔
README.md
Outdated
| Fatal: 13631488, | ||
| }, | ||
| DisableInlineFields: false, // If set to true, fields will not appear in columns ("inline") | ||
| DisableTimestamp: false, // Setting this to true will disable timestamps from appearing in the footer |
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.
Can we keep the old ordering (although TimestampLocale should still be directly after TimestampFormat)? It's more likely for time-related details to be changed than level colours, so time-related fields should take precedent.
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.
✔
README.md
Outdated
| DisableInlineFields: false, // If set to true, fields will not appear in columns ("inline") | ||
| DisableTimestamp: false, // Setting this to true will disable timestamps from appearing in the footer | ||
| TimestampFormat: timeStampFormat, // The timestamp takes this format; if it is unset, it will take logrus' default format | ||
| TimestampLocale: nil, // nil == time.Local, time.UTC, time.LoadLocation("America/New_York"), etc |
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'd prefer the comment // The timestamp uses this locale; if it is unset, it will use time.Local. By convention all usage has been left until later in the README.
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.
✔
README.md
Outdated
| Username | Replaces the default username of the webhook bot for the sent message only | Username unchanged | Any non-empty string (2-32 chars. inclusive) | ||
| Author | Adds an author field to the header if set | Author not set | Any non-empty string (1-256 chars inclusive) | ||
| DisableInlineFields | Inline means whether Discord will display the field in a column (with maximum three columns to a row). Setting this to `true` will cause Discord to display the field in its own row. | false | bool | ||
| DisableInlineFields | Inline means whether Discord will display the field in a column (with maximum three columns to a row). Setting this to `true` will cause Discord to display the field in its own row. | false | bool |
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.
As specified above, the previous ordering should be kept.
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.
✔
README.md
Outdated
| "os" | ||
| "github.com/Sirupsen/logrus" | ||
| "os" | ||
| "strings" |
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.
Having implemented the changes below, do make sure to remove unused imports.
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.
✔
discordrus_test.go
Outdated
| Author: "", // Setting this to a non-empty string adds the author text to the message header | ||
| DisableTimestamp: false, // Setting this to true will disable timestamps from appearing in the footer | ||
| TimestampFormat: "Jan 2 15:04:05.00000", // The timestamp takes this format; if it is unset, it will take logrus' default format | ||
| TimestampLocale: time.UTC, // The timestamp takes it's timezone from the provided locale |
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.
Previously, TimestampLocale was not specified so the entry's time would default to time.Local, so we should use time.Local instead.
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.
✔
|
@kz I believe all suggestions have been addressed, squashed, and pushed - thanks for the great feedback! |
|
FYI: |
|
Everything looks good to me! I'll merge now. |
Added support for displaying timestamps according to a timezone locale. This change should be fully backwards compatible with existing implementations of this library.
The Opts struct has a new field, TimestampLocale:
In addition, the
parseToJsonmethod was updated to support the Opts struct change: