question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gunicorn access logging is broken

See original GitHub issue

Hi all,

I originally found out about this bug which I was affected by here: https://github.com/tiangolo/uvicorn-gunicorn-starlette-docker/issues/1

Description

When using Gunicorn deployed with --access-logfile set and using the -k uvicorn.workers.UvicornWorker option, no access logs are sent to the access log file. Note that access logs do get sent to error logger (gunicorn.error) but they are supposed to go to access logger (gunicorn.access)

The Problem in Code

The issue is due to the following in httptools_impl.py:

https://github.com/encode/uvicorn/blob/15c4e9cfe2d996bd73ed6b542e44160f620b9519/uvicorn/protocols/http/httptools_impl.py#L436-L444

The problem is self.logger references a gunicorn logger: https://github.com/benoitc/gunicorn/blob/dc7b5d5c4876b49f86ea2460698a335d0f5ef7c9/gunicorn/glogging.py#L166 and the methods for logging there are only for the error logger (see the definition for the info method).

To use the access logger it would have to be self.logger.access_log.info(...) instead. I’ve confirmed this by making those changes manually and running the same gunicorn config and it fixes it. I believe hardcoding that piece will break the logging done by running uvicorn directly so I have not attached a PR. I am still looking into it, but if anyone has a good fix please go ahead.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
kireetcommented, Aug 26, 2019

hello, is there an ETA for this fix? Also will the gunicorn access log format setting be honored?

6reactions
Stigjbcommented, Nov 19, 2019

Is there a separate issue for the access log format? I can enable and disable access logs using accesslog in gunicorn_conf.py, but not change the log format with access_log_format.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is the Gunicorn access log format not working?
I have a fast API script running with the help of gunicorn, my access and error files are being created, however, I want...
Read more >
Gunicorn Documentation - Read the Docs
It provides error and access logging. You can provide your own logger by giving Gunicorn a Python path to a class that quacks...
Read more >
Deploying Gunicorn — Gunicorn 20.1.0 documentation
Gunicorn 19 introduced a breaking change concerning how REMOTE_ADDR is handled. ... To have access logs indicate the actual user IP when proxied, ......
Read more >
Unify Python logging for a Gunicorn/Uvicorn/FastAPI application
I didn't want to split logging configuration, Gunicorn configuration, and the rest of ... getLogger("gunicorn.access") self.access_logger.
Read more >
How to manage logs with Django, Gunicorn and NGINX
NGINX access logs · the IP is 123.45.67.89 · the request arrived at 26/Jul/2020:04:55:28 +0000 · the HTTP request method was GET ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found