From 9d7c69fb74283d15589d8ed970d5b3bd1cfee2f0 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Thu, 7 Feb 2013 22:35:42 +0100 Subject: [PATCH] Use logging.config.fileConfig() Instead of the monster I had built before. --- mediagoblin/init/celery/from_celery.py | 43 ++------------------------ 1 file changed, 2 insertions(+), 41 deletions(-) diff --git a/mediagoblin/init/celery/from_celery.py b/mediagoblin/init/celery/from_celery.py index 41fffa45..29037d10 100644 --- a/mediagoblin/init/celery/from_celery.py +++ b/mediagoblin/init/celery/from_celery.py @@ -16,9 +16,8 @@ import os import logging +import logging.config -from configobj import ConfigObj -from ConfigParser import RawConfigParser from celery.signals import setup_logging from mediagoblin import app, mg_globals @@ -40,45 +39,7 @@ def setup_logging_from_paste_ini(loglevel, **kw): raise IOError('{0} does not exist. Logging can not be set up.'.format( logging_conf_file)) - logging_conf = ConfigObj(logging_conf_file) - - config = logging_conf - - # Read raw config to avoid interpolation of formatting parameters - raw_config = RawConfigParser() - raw_config.readfp(open(logging_conf_file)) - - # Set up formatting - # Get the format string and circumvent configobj interpolation of the value - fmt = raw_config.get('formatter_generic', 'format') - - # Create the formatter - formatter = logging.Formatter(fmt) - - # Check for config values - if not config.get('loggers') or not config['loggers'].get('keys'): - print('No loggers found') - return - - # Iterate all teh loggers.keys values - for name in config['loggers']['keys'].split(','): - if not config.get('logger_{0}'.format(name)): - continue - - log_params = config['logger_{0}'.format(name)] - - qualname = log_params['qualname'] if 'qualname' in log_params else name - - if qualname == 'root': - qualname = None - - logger = logging.getLogger(qualname) - - level = getattr(logging, log_params['level']) - logger.setLevel(level) - - for handler in logger.handlers: - handler.setFormatter(formatter) + logging.config.fileConfig(logging_conf_file) setup_logging.connect(setup_logging_from_paste_ini) -- 2.25.1