mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
logging: Don't log static file requests
They are rarely useful. Refactor setup of static file serving to a method to avoid repetition. Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
c5ac291146
commit
8a7c849fbf
@ -85,6 +85,22 @@ def setup_logging():
|
|||||||
warnings.filterwarnings('default', '', ImportWarning)
|
warnings.filterwarnings('default', '', ImportWarning)
|
||||||
|
|
||||||
|
|
||||||
|
def _mount_static_directory(static_dir, static_url):
|
||||||
|
config = {
|
||||||
|
'/': {
|
||||||
|
'tools.staticdir.root': static_dir,
|
||||||
|
'tools.staticdir.on': True,
|
||||||
|
'tools.staticdir.dir': '.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
app = cherrypy.tree.mount(None, static_url, config)
|
||||||
|
# Don't log requests for static files as they are rarely useful.
|
||||||
|
app.log.access_log.propagate = False
|
||||||
|
app.log.error_log.propagate = False
|
||||||
|
|
||||||
|
logger.debug('Serving static directory %s on %s', static_dir, static_url)
|
||||||
|
|
||||||
|
|
||||||
def setup_server():
|
def setup_server():
|
||||||
"""Setup CherryPy server"""
|
"""Setup CherryPy server"""
|
||||||
logger.info('Setting up CherryPy server')
|
logger.info('Setting up CherryPy server')
|
||||||
@ -103,59 +119,23 @@ def setup_server():
|
|||||||
cherrypy.tree.graft(application, cfg.server_dir)
|
cherrypy.tree.graft(application, cfg.server_dir)
|
||||||
|
|
||||||
static_dir = os.path.join(cfg.file_root, 'static')
|
static_dir = os.path.join(cfg.file_root, 'static')
|
||||||
config = {
|
_mount_static_directory(static_dir, django.conf.settings.STATIC_URL)
|
||||||
'/': {
|
|
||||||
'tools.staticdir.root': static_dir,
|
|
||||||
'tools.staticdir.on': True,
|
|
||||||
'tools.staticdir.dir': '.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cherrypy.tree.mount(None, django.conf.settings.STATIC_URL, config)
|
|
||||||
logger.debug('Serving static directory %s on %s', static_dir,
|
|
||||||
django.conf.settings.STATIC_URL)
|
|
||||||
|
|
||||||
custom_static_dir = cfg.custom_static_dir
|
custom_static_dir = cfg.custom_static_dir
|
||||||
custom_static_url = '/plinth/custom/static'
|
custom_static_url = '/plinth/custom/static'
|
||||||
if os.path.exists(custom_static_dir):
|
if os.path.exists(custom_static_dir):
|
||||||
config = {
|
_mount_static_directory(custom_static_dir, custom_static_url)
|
||||||
'/': {
|
|
||||||
'tools.staticdir.root': custom_static_dir,
|
|
||||||
'tools.staticdir.on': True,
|
|
||||||
'tools.staticdir.dir': '.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cherrypy.tree.mount(None, custom_static_url, config)
|
|
||||||
logger.debug('Serving custom static directory %s on %s',
|
|
||||||
custom_static_dir, custom_static_url)
|
|
||||||
else:
|
else:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'Not serving custom static directory %s on %s, '
|
'Not serving custom static directory %s on %s, '
|
||||||
'directory does not exist', custom_static_dir, custom_static_url)
|
'directory does not exist', custom_static_dir, custom_static_url)
|
||||||
|
|
||||||
js_dir = '/usr/share/javascript'
|
_mount_static_directory('/usr/share/javascript', '/javascript')
|
||||||
js_url = '/javascript'
|
|
||||||
config = {
|
|
||||||
'/': {
|
|
||||||
'tools.staticdir.root': js_dir,
|
|
||||||
'tools.staticdir.on': True,
|
|
||||||
'tools.staticdir.dir': '.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cherrypy.tree.mount(None, js_url, config)
|
|
||||||
logger.debug('Serving javascript directory %s on %s', js_dir, js_url)
|
|
||||||
|
|
||||||
manual_dir = os.path.join(cfg.doc_dir, 'images')
|
manual_dir = os.path.join(cfg.doc_dir, 'images')
|
||||||
manual_url = '/'.join([cfg.server_dir, 'help/manual/images']) \
|
manual_url = '/'.join([cfg.server_dir, 'help/manual/images']) \
|
||||||
.replace('//', '/')
|
.replace('//', '/')
|
||||||
config = {
|
_mount_static_directory(manual_dir, manual_url)
|
||||||
'/': {
|
|
||||||
'tools.staticdir.root': manual_dir,
|
|
||||||
'tools.staticdir.on': True,
|
|
||||||
'tools.staticdir.dir': '.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cherrypy.tree.mount(None, manual_url, config)
|
|
||||||
logger.debug('Serving manual images %s on %s', manual_dir, manual_url)
|
|
||||||
|
|
||||||
for module_name, module in module_loader.loaded_modules.items():
|
for module_name, module in module_loader.loaded_modules.items():
|
||||||
module_path = os.path.dirname(module.__file__)
|
module_path = os.path.dirname(module.__file__)
|
||||||
@ -163,17 +143,8 @@ def setup_server():
|
|||||||
if not os.path.isdir(static_dir):
|
if not os.path.isdir(static_dir):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
config = {
|
|
||||||
'/': {
|
|
||||||
'tools.staticdir.root': static_dir,
|
|
||||||
'tools.staticdir.on': True,
|
|
||||||
'tools.staticdir.dir': '.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
urlprefix = "%s%s" % (django.conf.settings.STATIC_URL, module_name)
|
urlprefix = "%s%s" % (django.conf.settings.STATIC_URL, module_name)
|
||||||
cherrypy.tree.mount(None, urlprefix, config)
|
_mount_static_directory(static_dir, urlprefix)
|
||||||
logger.debug('Serving static directory %s on %s', static_dir,
|
|
||||||
urlprefix)
|
|
||||||
|
|
||||||
cherrypy.engine.signal_handler.subscribe()
|
cherrypy.engine.signal_handler.subscribe()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user