Commit 67aaee03 authored by Laurent Bachelier's avatar Laurent Bachelier 🐧 Committed by Romain Bignon

config: Use the same logger

This allows filtering and it is also nicer to have a prefix.
parent 3a9d0b88
......@@ -25,7 +25,6 @@ except ImportError:
from collections import OrderedDict
from decimal import Decimal
import logging
import os
import io
import sys
......@@ -33,6 +32,7 @@ import sys
from weboob.tools.compat import basestring, unicode
from .iconfig import IConfig
from .util import LOGGER
__all__ = ['INIConfig']
......@@ -50,7 +50,7 @@ class INIConfig(IConfig):
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 @@ class INIConfig(IConfig):
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
......
......@@ -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:
......
......@@ -18,7 +18,6 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
import logging
import os
import tempfile
import sys
......@@ -27,7 +26,7 @@ import weboob.tools.date
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 @@ class YamlConfig(IConfig):
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 = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment