From: Leandro Lucarella Date: Thu, 19 Jun 2008 03:28:50 +0000 (-0300) Subject: Add initialization logging configuration customization (refs #7). X-Git-Url: https://git.llucax.com/software/pymin.git/commitdiff_plain/649fa4aca75695f040ab03a96dd1c42d8d4be3c9?ds=inline Add initialization logging configuration customization (refs #7). Before user logging configuration can be loaded, pymin already can emit a lot of logging information. This patch provides a way to customize the logging configuration before the standard configuration framework take place. By default, it tries to read /etc/pymind/log.init.ini configuration file, unless PYMIND_LOGINITCONF environment variable is set, in which case the file specified by that variable it readed. If it fails to load the configuration file, it use a reasonble default. This is mostly useful for debugging/development purposes. --- diff --git a/pymind b/pymind index fa4fa36..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