Replies: 1 comment 1 reply
-
And import gunicorn.app.base
def handler_app(environ, start_response):
start_response("200 OK", [])
return [b'Works.']
class StandaloneApplication(gunicorn.app.base.BaseApplication):
def __init__(self, app, options=None):
self.options = options or {}
self.application = app
super().__init__()
def load_config(self):
config = {key: value for key, value in self.options.items()
if key in self.cfg.settings and value is not None}
for key, value in config.items():
self.cfg.set(key.lower(), value)
def load(self):
return self.application
def run(self):
if self.cfg.print_config: # <<<<<<<<<<<<<<<<<<<<<<< print_config added here
print(self.cfg)
super().run()
if __name__ == '__main__':
options = {
'bind': '%s:%s' % ('[::1]', '8080'),
'workers': 1,
"print_config": True,
"access_log_format": 'this is my custom log format - %({user-agent}i)s',
"enable_stdio_inheritance": True,
"accesslog": "-",
"errorlog": "-",
}
StandaloneApplication(handler_app, options).run() # python3 app.py
access_log_format = this is my custom log format - %({user-agent}i)s
[..]
[2025-04-08 19:39:28 +0200] [401927] [INFO] Starting gunicorn 23.0.0
[2025-04-08 19:39:28 +0200] [401927] [INFO] Listening at: http://[::1]:8080 (401927)
[2025-04-08 19:39:28 +0200] [401927] [INFO] Using worker: sync
[2025-04-08 19:39:28 +0200] [401929] [INFO] Booting worker with pid: 401929
# echo -ne "GET / HTTP/1.1\r\nUser-Agent: foo\r\n\r\n" | nc.openbsd "::1" 8080
this is my custom log format - foo |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a FastAPI application that I run with gunicorn with a runner similar to https://docs.gunicorn.org/en/stable/custom.html.
I'm trying to print some header values to I added
"access_log_format": '%({user-agent}i)s'
to the options dict. To my surprise the access log is the same as it is without that line.Some other settings also didn't work. For example adding
"print_config": True,
doesn't do anything.Some settings like
bind
,workers
,worker_class
,accesslog
appear to work fine.Beta Was this translation helpful? Give feedback.
All reactions