-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
enhancement to AccessLogger #1303
Conversation
populates "extra" dict for clients
|
||
extra = {name: value for name, value in fmt_info} | ||
self.logger.info(self._log_format % | ||
tuple([value for _, value in fmt_info]), |
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.
is it fmt_info.values()
?
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.
not currently as fmt_info is a tuple of tuples to keep items in format order. Would you prefer it be a OrderedDict/namedtuple?
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.
Aaah, got it.
But if you'll return just extra
OrderedDict
from _format_line
the code may look better.
Also keys for headers/envvars from dicts like extra={'%{None}i': '-', '%{SPAM}e': 'EGGS', '%{Content-Length}o': 123, '%{User-Agent}i': 'Mock/1.0'}
looks... Well, they looks non-intuitive.
I would expect something like input_header[User-Agent]
instead of cryptic %{User-Agent}i
.
Maybe constructing _log_format
as format accepting params by name in new-styled .format
form like "{status} {remote_address} {input_headers[User-Agent]}"
makes sense?
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.
Actually reading the docs for the new formatter it seems like the logging module in python 3.2+ supports the new '{}' style formatting, making this solution a win-win and removes any hesitations I had for this solution, yay! I'll code something up shortly.
ok I think this is what we want, extra will contain things like: {"response_status": 200,
"remote_address": "127.0.0.1",
"request_time_frac": "0.317883",
"request_header": {
"User-Agent": "python-requests/2.11.1"
},
"first_request_line": "POST /v1/locations HTTP/1.1",
"response_size": 83} this way users can have a formatter as follows:
we set the root log handler so if we have the correct format everything "just works" ™️ :) |
I'm not sure if it's doable but it may be worth thinking if it's possible to use a new-style formatter and having the logging system now compose the logging message based on this new |
Awesome! |
also fix PEP warning in setup.py
Current coverage is 96.68% (diff: 100%)@@ master #1303 diff @@
==========================================
Files 29 29
Lines 6497 6515 +18
Methods 0 0
Messages 0 0
Branches 1090 1094 +4
==========================================
- Hits 6400 6299 -101
- Misses 47 148 +101
- Partials 50 68 +18
|
Thanks! |
populates "extra" dict for clients