mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-11 09:04:54 +00:00
web_server: Log requests to WSGI app
- This is quite useful for debugging even on production machines. - CherryPy can't be used for logging as grafting a WSGI application bypasses the usual mechanisms of logging. - Keep requests for static files turned off in CherryPy as these are not very useful. Tests: - Making a request print an INFO message on the log with method and path after the /freedombox part. Logs can be seen in systemd journal. - Requests for static files are not logged. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
854916c54c
commit
0d579012d7
@ -72,8 +72,19 @@ def init():
|
||||
'engine.autoreload.match': AUTORELOAD_REGEX,
|
||||
})
|
||||
|
||||
def _logging_middleware(application):
|
||||
"""A WSGI middleware to log messages before executing them."""
|
||||
|
||||
def _wrapper(environ, start_response):
|
||||
"""Log request, then hand control to original app."""
|
||||
logger.info("%s %s", environ['REQUEST_METHOD'],
|
||||
environ['PATH_INFO'])
|
||||
return application(environ, start_response)
|
||||
|
||||
return _wrapper
|
||||
|
||||
application = web_framework.get_wsgi_application()
|
||||
cherrypy.tree.graft(application, cfg.server_dir)
|
||||
cherrypy.tree.graft(_logging_middleware(application), cfg.server_dir)
|
||||
|
||||
static_dir = os.path.join(cfg.file_root, 'static')
|
||||
_mount_static_directory(static_dir, web_framework.get_static_url())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user