Skip to content

Instantly share code, notes, and snippets.

@chilledornaments
Created January 10, 2020 16:45
Show Gist options
  • Save chilledornaments/7b03cfcbc7d8d81525546a94bf497632 to your computer and use it in GitHub Desktop.
Save chilledornaments/7b03cfcbc7d8d81525546a94bf497632 to your computer and use it in GitHub Desktop.
Gunicorn logging with custom values
import socket
from os import environ
hostname = socket.gethostname()
"""
Logging env vars with %({env_var}e)s hasn't worked for me in gunicorn 20.0.4
"""
access_one = '%({X-Forwarded-For}i)s %(r)s "%(s)s" "%(b)s" "%(a)s" "%(p)s" "%(D)s"'
access_two = '"{}" app={} env={}'.format(socket.gethostname(), environ.get("APP_NAME"), environ.get("ROLLBAR_ENV"))
access_log_format = "{} {}".format(access_one, access_two)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment