From b6d445a5a1988bffe08a4eb1fb4b903bbb194b15 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Sat, 28 Jun 2014 22:16:46 +0300 Subject: [PATCH] Set global logging configuration from a Paste config. Since gunicorn.app.pasterapp.{run, paste_server} are deprecated, there is no way to configure the logging module from a Paste config file. --- gunicorn/app/pasterapp.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gunicorn/app/pasterapp.py b/gunicorn/app/pasterapp.py index 2c4d1ef4f..0664462c6 100644 --- a/gunicorn/app/pasterapp.py +++ b/gunicorn/app/pasterapp.py @@ -20,6 +20,17 @@ from gunicorn import util +def _configure_logging_from_paste_config(paste_file): + logger_cfg_file = paste_file.split(':')[1] + cfg_parser = ConfigParser.ConfigParser() + cfg_parser.read([logger_cfg_file]) + if cfg_parser.has_section('loggers'): + from logging.config import fileConfig + config_file = os.path.abspath(logger_cfg_file) + fileConfig(config_file, dict(__file__=config_file, + here=os.path.dirname(config_file))) + + def paste_config(gconfig, config_url, relative_to, global_conf=None): # add entry to pkg_resources sys.path.insert(0, relative_to) @@ -41,6 +52,9 @@ def paste_config(gconfig, config_url, relative_to, global_conf=None): cfg['umask'] = int(lc.get('umask', 0)) cfg['default_proc_name'] = gc.get('__file__') + # init logging configuration + _configure_logging_from_paste_config(config_url) + for k, v in gc.items(): if k not in gconfig.settings: continue