mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Merge pull request #941 from benoitc/unify-paste-logging
Set logconfig default to paster more trivially
This commit is contained in:
commit
fcb700ca66
@ -21,15 +21,10 @@ from gunicorn.config import Config, get_default_config_file
|
|||||||
from gunicorn import util
|
from gunicorn import util
|
||||||
|
|
||||||
|
|
||||||
def _configure_logging_from_paste_config(paste_file):
|
def _has_logging_config(paste_file):
|
||||||
logger_cfg_file = paste_file.split(':')[1]
|
|
||||||
cfg_parser = ConfigParser.ConfigParser()
|
cfg_parser = ConfigParser.ConfigParser()
|
||||||
cfg_parser.read([logger_cfg_file])
|
cfg_parser.read([paste_file])
|
||||||
if cfg_parser.has_section('loggers'):
|
return 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):
|
def paste_config(gconfig, config_url, relative_to, global_conf=None):
|
||||||
@ -39,7 +34,7 @@ def paste_config(gconfig, config_url, relative_to, global_conf=None):
|
|||||||
|
|
||||||
config_url = config_url.split('#')[0]
|
config_url = config_url.split('#')[0]
|
||||||
cx = loadwsgi.loadcontext(SERVER, config_url, relative_to=relative_to,
|
cx = loadwsgi.loadcontext(SERVER, config_url, relative_to=relative_to,
|
||||||
global_conf=global_conf)
|
global_conf=global_conf)
|
||||||
gc, lc = cx.global_conf.copy(), cx.local_conf.copy()
|
gc, lc = cx.global_conf.copy(), cx.local_conf.copy()
|
||||||
cfg = {}
|
cfg = {}
|
||||||
|
|
||||||
@ -54,7 +49,9 @@ def paste_config(gconfig, config_url, relative_to, global_conf=None):
|
|||||||
cfg['default_proc_name'] = gc.get('__file__')
|
cfg['default_proc_name'] = gc.get('__file__')
|
||||||
|
|
||||||
# init logging configuration
|
# init logging configuration
|
||||||
_configure_logging_from_paste_config(config_url)
|
config_file = config_url.split(':')[1]
|
||||||
|
if _has_logging_config(config_file):
|
||||||
|
cfg.setdefault('logconfig', config_file)
|
||||||
|
|
||||||
for k, v in gc.items():
|
for k, v in gc.items():
|
||||||
if k not in gconfig.settings:
|
if k not in gconfig.settings:
|
||||||
|
|||||||
@ -199,8 +199,11 @@ class Logger(object):
|
|||||||
|
|
||||||
if cfg.logconfig:
|
if cfg.logconfig:
|
||||||
if os.path.exists(cfg.logconfig):
|
if os.path.exists(cfg.logconfig):
|
||||||
fileConfig(cfg.logconfig, defaults=CONFIG_DEFAULTS,
|
defaults = CONFIG_DEFAULTS.copy()
|
||||||
disable_existing_loggers=False)
|
defaults['__file__'] = cfg.logconfig
|
||||||
|
defaults['here'] = os.path.dirname(cfg.logconfig)
|
||||||
|
fileConfig(cfg.logconfig, defaults=defaults,
|
||||||
|
disable_existing_loggers=False)
|
||||||
else:
|
else:
|
||||||
msg = "Error: log config '%s' not found"
|
msg = "Error: log config '%s' not found"
|
||||||
raise RuntimeError(msg % cfg.logconfig)
|
raise RuntimeError(msg % cfg.logconfig)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user