-
-
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
Fix access_log_format in GunicornWebWorker
#1117
Conversation
@asvetlov, does this change reflect the workaround you suggested? |
Current coverage is 98.15% (diff: 100%)@@ master #1117 diff @@
==========================================
Files 28 28
Lines 6371 6381 +10
Methods 0 0
Messages 0 0
Branches 1070 1072 +2
==========================================
+ Hits 6253 6263 +10
Misses 63 63
Partials 55 55
|
@@ -159,6 +161,11 @@ def _create_ssl_context(cfg): | |||
ctx.set_ciphers(cfg.ciphers) | |||
return ctx | |||
|
|||
def _fix_log_format(self, source_format, default_format): | |||
if re.search(r'%\([^\)]+\)', source_format): | |||
return default_format |
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.
Oh, no.
Silent format replacement should be performed only if source format is exactly default gunicorn log format, %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"
according to the doc.
For all other gunicorn-styled but not default formats ValueError
should be raised.
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.
Ha, now I got you. The comment in issue was unclear to me. Going to fix this according to your input. Thanks!
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.
5112495
to
961dd21
Compare
return self.DEFAULT_AIOHTTP_LOG_FORMAT | ||
elif re.search(r'%\([^\)]+\)', source_format): | ||
raise ValueError('Gunicorn style using `%(name)s` ' | ||
'is not supported for the log formatting.') |
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 append http://aiohttp.readthedocs.io/en/stable/logging.html#format-specification link to exception text.
Now exception states that something is wrong but doesn't point on solution.
But it's most likely configuration problem, not programming error.
The exception will be caught by admin or devops, not software developer.
I suggest to provide very detailed error info in these cases.
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.
Agreed. Thanks for the point. Added a link and a text with correct directive.
- Replace default gunicorn's access log format with the default aiohttp's one. - Use regular expression to check if the log format passed as a gunicorn's option `access_logformat` uses Gunicorn's formatting style and in this case raise a `ValueError`. - Add a note describing this behavior to the `Logging` section of the documentation.
961dd21
to
6111338
Compare
Thanks! |
What do these changes do?
It's intended to check
GunicornWebWorker.cfg.access_log_format
.If its value is default Gunicorn's format string, it will be replaced with default aiohttp's log format string to create request handler with.
If it doesn't use default Gunicorn's format string but still sticks to Gunicorn's specification with format options in form of
%(name)s
, theValueError
will be thrown with an appropriate message.Logging
section of the documentation.Are there changes in behavior for the user?
Should fix #705 and show correct output in the access log.
Related issue number
#705
Checklist