X-Git-Url: https://git.llucax.com/software/pymin.git/blobdiff_plain/1b0d4cdcf9d82572cb7fac7e53513316196a8d39..f79fe24d7dae27f6cb31745f24256b01755aad8d:/pymind diff --git a/pymind b/pymind index da7b218..78939f0 100755 --- a/pymind +++ b/pymind @@ -1,15 +1,21 @@ #!/usr/bin/env python # vim: set encoding=utf-8 et sw=4 sts=4 : -import logging, logging.config ; log = logging.getLogger('pymind') -# default logging configuration -# (this is used before the user configuration file gets parsed) -logging.basicConfig(format='%(levelname)s: %(message)s') - import os import sys from formencode import Invalid, validators as V +import logging, logging.config ; log = logging.getLogger('pymind') +# default logging configuration +# (this is used before the user configuration file gets parsed) +try: + # first we try to load a log config file + default = '/etc/pymin/log.init.ini' + logging.config.fileConfig(os.getenv('PYMIND_LOGINITCONF', default)) +except: + # then we try to load a reasonable default + logging.basicConfig(format='%(levelname)s: %(message)s') + from pymin.config import OptionGroup, Option, ConfigOption, ListOption from pymin.config import load_config, options from pymin.config import ConfigError, MissingSectionHeaderError, ParsingError @@ -133,6 +139,12 @@ def build_root(config, args, services): def setup_logging(config_files): + # XXX: this is a hack for re-enabling loggers not configured via + # fileConfig(). This function disable all existing loggers that + # has no configuration specified in the config file, so we have + # to re-enable the by hand. + # See Python bug 3136: http://bugs.python.org/issue3136 + existing = logging.root.manager.loggerDict.keys() loaded_files = 0 for f in config_files: try: @@ -145,6 +157,9 @@ def setup_logging(config_files): loaded_files += 1 if not loaded_files: log.warning('no log config file loaded') + # XXX: finish the hack commented above + for log in existing: + logging.root.manager.loggerDict[log].disabled = 0 def main():