Example #1
0
    def test(self):
        conf = b"""
# do not disable other loggers by default.
disable_existing_loggers: False

# please do not change version, it is an internal variable used by Python.
version: 1

handlers:
    rotating_files:
        class: logging.handlers.RotatingFileHandler
        filename: /pyemma.log

loggers:
    pyemma:
        level: INFO
        handlers: [rotating_files]
        """
        with NamedTemporaryFile(delete=False) as f:
            f.write(conf)
            f.close()
            with mock.patch('pyemma.util.log.open', create=True) as mock_open:
                mock_open.return_value = open(f.name)

                log.setup_logging(config)
                assert logging.getLogger('pyemma').handlers[0].baseFilename.startswith(config.cfg_dir)
Example #2
0
    def __init__(self):
        self._cache = {}

        # this is a ConfigParser instance
        self._conf_values = None

        self._old_level = None

        # note we do not invoke the cfg_dir setter here, because we do not want anything to be created/copied yet.
        # first check if there is a config dir set via environment
        if 'PYEMMA_CFG_DIR' in os.environ:
            # TODO: probe?
            self._cfg_dir = os.environ['PYEMMA_CFG_DIR']
        # try to read default cfg dir
        elif os.path.isdir(self.DEFAULT_CONFIG_DIR) and os.access(
                self.DEFAULT_CONFIG_DIR, os.W_OK):
            self._cfg_dir = self.DEFAULT_CONFIG_DIR
        # use defaults, have no cfg_dir set.
        else:
            self._cfg_dir = ''
        try:
            self.load()
        except RuntimeError as re:
            warnings.warn(
                "unable to read default configuration file. Logging and "
                " progress bar handling could behave bad! Error: %s" % re)

        from pyemma.util.log import setup_logging, LoggingConfigurationError
        try:
            setup_logging(self)
        except LoggingConfigurationError as e:
            warnings.warn(
                "Error during logging configuration. Logging might not be functional!"
                "Error: %s" % e)
Example #3
0
 def tearDown(self):
     # reset logging
     log.setup_logging(config)