-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
structlog: migrate application code to better logging #8705
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
structlog: migrate application code to better logging #8705
Conversation
d546298
to
8eb7800
Compare
Initial work to migrate our application to structlog for better logging, making them compatible with New Relic's integration. There are more work that can be done here to make it better. For example, more usage of `log.bind` to avoid repetition. Besides, rewriting some log message and reduce them to have more Canonical Log Lines (https://www.structlog.org/en/stable/logging-best-practices.html#canonical-log-lines) instead.
8eb7800
to
1110839
Compare
Logs coming from `logging.getLogger` (from other applications) have the same structure that the ones logged by us via `structlog`.
84ff22d
to
9b261ab
Compare
Use a custom renderer to match the structure we want: ``` %programname[%processid] [%level] %message [%logger:%linenumber] %structureddata ``` By default, rsyslog will prepend ``` %timestamp %hostname ``` and it will look exactly as we want.
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 a huge change that involved core functionality and massive logging changes, which I was hoping to avoid. I am going to approve and merge it because I assume it's well-tested, but this PR is basically impossible to review as it currently is without a huge amount of time unfortunately.
I would have loved to at least see the code changes and the mass migration done in different PR's or some other way to make it reviewable.
|
||
def __exit__(self, exc, value, tb): | ||
log.bind(project_slug=self.name) |
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.
Does this unbind it, since we're also setting this on __enter__
? Could definitely use a comment.
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 explained this/a similar case in https://github.com/readthedocs/readthedocs-corporate/pull/1336#issuecomment-977167702
Initial work to migrate our application to structlog for better logging, making
them compatible with New Relic's integration.
There is more work that can be done here to make it better. For example, more
usage of
log.bind
to avoid repetition. Besides, rewriting some log messages andreducing them to have more Canonical Log
Lines (https://www.structlog.org/en/stable/logging-best-practices.html#canonical-log-lines)
instead.
The migration steps followed are described in #8689. Also note that this PR is based on that one.