Skip to content

Commit d580c39

Browse files
authored
Configure gunicorn access log (#246)
* 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.
1 parent 65c908c commit d580c39

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

gunicorn.conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,11 @@
5050
# This should be set to a value less than the 30 second Heroku dyno shutdown timeout:
5151
# https://devcenter.heroku.com/articles/dyno-shutdown-behavior
5252
graceful_timeout = 20
53+
54+
# Enable logging of incoming requests to stdout.
55+
accesslog = "-"
56+
57+
# Adjust which fields are included in the access log, and make it use the Heroku logfmt
58+
# style. The `X-Request-Id` and `X-Forwarded-For` headers are set by the Heroku Router:
59+
# https://devcenter.heroku.com/articles/http-routing#heroku-headers
60+
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 commit comments

Comments
 (0)