-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add structured logger (#54) #1467
Add structured logger (#54) #1467
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1467 +/- ##
==========================================
+ Coverage 69.93% 70.23% +0.29%
==========================================
Files 94 94
Lines 6447 6441 -6
==========================================
+ Hits 4509 4524 +15
+ Misses 1558 1533 -25
- Partials 380 384 +4
Continue to review full report at Codecov.
|
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.
👍 couple questions but overall good change
@nishkrishnan can you show the before/after for what the logs will look like? |
added in the PR description |
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.
This is great! The only concern I have is potentially breaking existing integration pipelines for the Atlantis users. I don't think it is a major issue.
Do you mean folks that are parsing the logs somehow? |
yeah that's what he means. Though it's hard to believe given the existing format is human readable not so much machine readable. This will be released with v0.17.0 so since it's a major release, we can bring this up in the changelog as a backwards incompatibility. |
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.
Two thoughts:
- I was thinking that maybe folks would like a -log-format option to view the non-json logs in case they prefer the old view
- I was wondering if we need the json: {} key, instead can we just have additional k/v's appended and not nested under the json key?
Adds some additional complexity here to support both loggers, but I can do that if you feel strongly. was thinking this is just arguably better and should probably be the standard. Also, keep in mind that the history surfaced on PRs is still in the old format for readability so this only affects customers that read the logs on the server directly.
I gotta say this was kind of specific to my company as our log parser by default looks for the json key and indexes all the fields under them. I think this makes sense because otherwise you would need to go back and edit the parser each time as you add a new field to your structured log. If you feel strongly about this I can remove it. If not I can add documentation around this. |
I think this depends on the size of the company. If you're large and you already have log ingress with json parsing then yes. But if you're most likely to be looking at the logs as is, or testing out locally, then it's harder to read as JSON. I wonder if there's some detection if it's running in a terminal or not. I don't think this should block this PR.
Ahh interesting. Is that a standard way to do it? If you're going to automatically index all fields under |
Yeah this is fair, it's worth noting though that the test version of this logger (Nooplogger) actually prints in human readable format so for the tests it looks really nice for debugging but yes readability would take a hit when running the server locally.
having a nested key avoids you indexing fields you wouldn't want to index such as the message itself. Unsure whether this is a standard, it's just what Lyft does 🤷 I think I'll just ship as part of the 0.17 release and we can get feedback on whether to bring back the human readable format or not. Something like this: https://pkg.go.dev/go.uber.org/zap#NewDevelopmentConfig seems it could be used for local servers since it doesn't use json encoding. |
Hey @nishkrishnan, could you give any suggestions for how to enable and forward logs? For example, do I need to supply atlantis with a specific config or parameter to enabling logging? What events can I capture? And are logs saved to file or can I forward them somehow? Or will I need to implement something more custom? Apologies if this is super obvious there's not much info in the docs when it comes to logging! |
This is two changes:
SimpleLogger
with it's interfaceSimpleLogging
which makes it easier to swap out loggers going forwardSimpleLogger
in favor ofStructuredLogger
which allows us to better analyze logs in our log management system we choose.Right now the real changes are scoped to
simple_logger.go
andlogging_test
the rest of the changes are just interface changes + test changes to support the new constructor forNoopLogger
Before:
After:
Note: As a base logger I'm using zap