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
|
aiohttp/worker.py
Outdated
|
|
||
| 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.
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.
Ha, now I got you. The comment in issue was unclear to me. Going to fix this according to your input. Thanks!
5112495 to
961dd21
Compare
aiohttp/worker.py
Outdated
| 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.
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.
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, theValueErrorwill be thrown with an appropriate message.Loggingsection 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