From 67aaee031de1dd7a94f52346821690211fd72fb3 Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Fri, 8 Nov 2019 16:21:36 +0100 Subject: [PATCH] config: Use the same logger This allows filtering and it is also nicer to have a prefix. --- weboob/tools/config/iniconfig.py | 12 ++++++------ weboob/tools/config/util.py | 6 +++++- weboob/tools/config/yamlconfig.py | 9 ++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/weboob/tools/config/iniconfig.py b/weboob/tools/config/iniconfig.py index 9765dac907..54fef239e2 100644 --- a/weboob/tools/config/iniconfig.py +++ b/weboob/tools/config/iniconfig.py @@ -25,7 +25,6 @@ from collections import OrderedDict from decimal import Decimal -import logging import os import io import sys @@ -33,6 +32,7 @@ from weboob.tools.compat import basestring, unicode from .iconfig import IConfig +from .util import LOGGER __all__ = ['INIConfig'] @@ -50,7 +50,7 @@ def load(self, default={}): self.values = OrderedDict(default) if os.path.exists(self.path): - logging.debug(u'Loading application configuration file: %s.' % self.path) + LOGGER.debug(u'Loading application configuration file: %s.' % self.path) if sys.version_info.major < 3: self.config.readfp(io.open(self.path, "r", encoding='utf-8')) else: @@ -66,14 +66,14 @@ def load(self, default={}): first = True for key, value in self.config.items(DEFAULTSECT): if first: - logging.warning('The configuration file "%s" uses an old-style' % self.path) - logging.warning('Please rename the %s section to %s' % (DEFAULTSECT, self.ROOTSECT)) + LOGGER.warning('The configuration file "%s" uses an old-style' % self.path) + LOGGER.warning('Please rename the %s section to %s' % (DEFAULTSECT, self.ROOTSECT)) first = False self.set(key, value) - logging.debug(u'Application configuration file loaded: %s.' % self.path) + LOGGER.debug(u'Application configuration file loaded: %s.' % self.path) else: self.save() - logging.debug(u'Application configuration file created with default values: %s. ' + LOGGER.debug(u'Application configuration file created with default values: %s. ' 'Please customize it.' % self.path) return self.values diff --git a/weboob/tools/config/util.py b/weboob/tools/config/util.py index 32bf1e93cd..a01a9f116d 100644 --- a/weboob/tools/config/util.py +++ b/weboob/tools/config/util.py @@ -20,8 +20,12 @@ import os from datetime import datetime +from weboob.tools.log import getLogger -__all__ = ['replace', 'time_buffer'] +__all__ = ['LOGGER', 'replace', 'time_buffer'] + + +LOGGER = getLogger('weboob.config') try: diff --git a/weboob/tools/config/yamlconfig.py b/weboob/tools/config/yamlconfig.py index 59c3aed4e5..55f8953b7f 100644 --- a/weboob/tools/config/yamlconfig.py +++ b/weboob/tools/config/yamlconfig.py @@ -18,7 +18,6 @@ # along with weboob. If not, see . -import logging import os import tempfile import sys @@ -27,7 +26,7 @@ import yaml from .iconfig import ConfigError, IConfig -from .util import replace +from .util import LOGGER, replace try: from yaml import CLoader as Loader @@ -67,14 +66,14 @@ def __init__(self, path): def load(self, default={}): self.values = default.copy() - logging.debug(u'Loading application configuration file: %s.' % self.path) + LOGGER.debug(u'Loading application configuration file: %s.' % self.path) try: with open(self.path, 'r') as f: self.values = yaml.load(f, Loader=self.LOADER) - logging.debug(u'Application configuration file loaded: %s.' % self.path) + LOGGER.debug(u'Application configuration file loaded: %s.' % self.path) except IOError: self.save() - logging.debug(u'Application configuration file created with default values: %s. Please customize it.' % self.path) + LOGGER.debug(u'Application configuration file created with default values: %s. Please customize it.' % self.path) if self.values is None: self.values = {} -- GitLab