Skip to content
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

access log format is invalid when using gunicorn worker #705

Closed
sontek opened this issue Dec 25, 2015 · 10 comments · Fixed by #1117
Closed

access log format is invalid when using gunicorn worker #705

sontek opened this issue Dec 25, 2015 · 10 comments · Fixed by #1117
Labels

Comments

@sontek
Copy link

sontek commented Dec 25, 2015

It seems you have to pass in --access-logformat='%a %l %u %t "%r" %s %b "%{Referrer}i" "%{User-Agent}i"' to gunicorn for logging to work, they default format from gunicorn is "%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" which doesn't work with aiohttp

@zeroaltitude
Copy link

I have found this problem too, just today. Thank you for the workaround.

@FrederikNJS
Copy link

FrederikNJS commented Apr 20, 2016

Just ran into this issue... Took me a couple of hours to find this answer. Thanks for the workaround, I was starting to get grey hairs.

@anthonylau
Copy link

benoitc/gunicorn#1300
might be related, can't get metrics on statsd

@miedzinski
Copy link

This is still an issue.

@tumb1er
Copy link
Contributor

tumb1er commented Aug 23, 2016

Gunicorn config defaults are invalid for aiohttp.helpers.AccessLogger.log_format. To fix this, you need to change at least %a behavior, and may be other format arguments that intersect between http://docs.gunicorn.org/en/stable/settings.html#access-log-format and http://aiohttp.readthedocs.io/en/stable/logging.html#format-specification.
This at least backward-incompatible change, but it'll be very nice to fix it finally.

Other option is to pass access logger class to RequestHandler arguments from gunicorn worker, but it's too complicated.

@asvetlov
Copy link
Member

We can make a workaround.

  1. Replace default gunicorn logger format with default aiohttp one on worker initialization.
    Follow step may be:
  2. Add a checker for gunicorn logging style and raise an explicit error on worker initialization
    It can be just regexp for %(name)s parts in logging spec.

We can also add a support for gunicorn style but it requires much more work and the solution is very complicated from my perspective.

@f0t0n maybe you have an interest in fixing the issue?

@f0t0n
Copy link
Contributor

f0t0n commented Aug 24, 2016

@asvetlov Gunicorn's Arbiter reads the gunicorn config, then creates a logger and passes it to worker's constructor.

  1. Replace default gunicorn logger format with default aiohttp one on worker initialization.

In this way if we call self.log.setFormatter() inside worker's constructor with formatter that uses default aiohttp's format string aiohttp.helpers.LOG_FORMAT we're not able to read one from gunicorn config since it's too late to override.

  1. Add a checker for gunicorn logging style and raise an explicit error on worker initialization
    It can be just regexp for %(name)s parts in logging spec.

Also I don't see a correct way to retrieve a format string from logger like self.log.handlers[0].formatter._fmt since this string is a protected member of logging.Formatter class.

@tumb1er
Copy link
Contributor

tumb1er commented Aug 24, 2016

access_logformat from gunicorn config is passed from GunicornWebWorker to ServerHttpProtocol, which constructs AccessLogger "wrapper" with gunicorn (invalid) default format instead of aiohttp's one.

For me, access logs work with:

gunicorn --worker-class=aiohttp.worker.GunicornWebWorker 
  --access-logformat="..." 
  --log-config=logging.conf

logging.conf part:

[logger_gunicorn.access]
level=INFO
handlers=access_file
propagate=0
qualname=gunicorn.access

[handler_access_file]
class=logging.handlers.TimedRotatingFileHandler
formatter=access
args=('/data/logs/access.log', 'midnight')

[formatter_access]
format=%(message)s # That's what glogger receives from AccessLogger wrapper
class=logging.Formatter

@f0t0n
Copy link
Contributor

f0t0n commented Aug 24, 2016

Ok, I'll try to work with self.cfg.access_log_format.

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants