Skip to content

Commit

Permalink
Configure gunicorn access log (#246)
Browse files Browse the repository at this point in the history
* Explicitly enable the access log (since currently it's only enabled
  when using the classic Python buildpack, and not locally or when
  using the Python CNB).
* Customise the gunicorn access log format to make it use the Heroku
  logfmt style, and to improve which fields are included.

Before:

```
2024-12-08T16:23:33.457957+00:00 app[web.1]: ::ffff:10.1.50.245 - - [08/Dec/2024:16:23:33 +0000] "GET / HTTP/1.1" 200 9585 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:134.0) Gecko/20100101 Firefox/134.0"
```

After:

```
2024-12-08T16:32:47.618296+00:00 app[web.1]: gunicorn method=GET path="/" status=200 duration=14ms request_id=e45f9c86-d6d8-4b79-937e-18c0b6bf859e fwd="123.456.789.0" user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:134.0) Gecko/20100101 Firefox/134.0"
```

Ref heroku/buildpacks-python#4.
GUS-W-17316745.
  • Loading branch information
edmorley authored Dec 8, 2024
1 parent 65c908c commit d580c39
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gunicorn.conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@
# This should be set to a value less than the 30 second Heroku dyno shutdown timeout:
# https://devcenter.heroku.com/articles/dyno-shutdown-behavior
graceful_timeout = 20

# Enable logging of incoming requests to stdout.
accesslog = "-"

# Adjust which fields are included in the access log, and make it use the Heroku logfmt
# style. The `X-Request-Id` and `X-Forwarded-For` headers are set by the Heroku Router:
# https://devcenter.heroku.com/articles/http-routing#heroku-headers
access_log_format = 'gunicorn method=%(m)s path="%(U)s" status=%(s)s duration=%(M)sms request_id=%({x-request-id}i)s fwd="%({x-forwarded-for}i)s" user_agent="%(a)s"'

0 comments on commit d580c39

Please sign in to comment.