Tres Seaver
2011-05-17 d6b53f96464e73165af86f1bdf8df1fbc2a2b8a9
Enabled standard use of logging module's configuration mechanism.

See http://docs.python.org/dev/howto/logging.html#configuring-logging-for-a-library

Thanks to jgoldsmith for the patch: http://bugs.repoze.org/issue178
3 files modified
49 ■■■■■ changed files
CHANGES.txt 5 ●●●●● patch | view | raw | blame | history
repoze/who/config.py 8 ●●●●● patch | view | raw | blame | history
repoze/who/tests/test_config.py 36 ●●●●● patch | view | raw | blame | history
CHANGES.txt
@@ -4,6 +4,11 @@
Unreleased
----------
- Enabled standard use of logging module's configuration mechanism.
  See http://docs.python.org/dev/howto/logging.html#configuring-logging-for-a-library
  Thanks to jgoldsmith for the patch: http://bugs.repoze.org/issue178
- ``repoze.who.plugins.htpasswd``:  defend against timing-based attacks.
repoze/who/config.py
@@ -129,6 +129,11 @@
                                     )
class NullHandler(logging.Handler):
    def emit(self, record):
        pass
_LEVELS = {'debug': logging.DEBUG,
           'info': logging.INFO,
           'warning': logging.WARNING,
@@ -184,6 +189,9 @@
            log_stream = sys.stdout
        else:
            log_stream = open(log_file, 'wb')
    else:
        log_stream = logging.getLogger('repoze.who')
        log_stream.addHandler(NullHandler())
    if log_level is None:
        log_level = logging.INFO
repoze/who/tests/test_config.py
@@ -405,8 +405,44 @@
        middleware = factory(app, global_conf, config_file=path,
                             log_file=logfile)
        self.assertEqual(middleware.logger.getEffectiveLevel(), logging.INFO)
        handlers = middleware.logger.handlers
        self.assertEqual(len(handlers), 1)
        self.failUnless(isinstance(handlers[0], logging.StreamHandler))
        self.assertEqual(handlers[0].stream.name, logfile)
        logging.shutdown()
    def test_sample_config_wo_log_file(self):
        import logging
        from repoze.who.config import NullHandler
        app = DummyApp()
        factory = self._getFactory()
        path = self._getTempfile(SAMPLE_CONFIG)
        global_conf = {'here': '/'}
        middleware = factory(app, global_conf, config_file=path)
        self.assertEqual(middleware.logger.getEffectiveLevel(), 0)
        handlers = middleware.logger.handlers
        self.assertEqual(len(handlers), 1)
        self.failUnless(isinstance(handlers[0], NullHandler))
        logging.shutdown()
class NullHandlerTests(unittest.TestCase):
    def _getTargetClass(self):
        from repoze.who.config import NullHandler
        return NullHandler
    def _makeOne(self):
        return self._getTargetClass()()
    def test_inheritance(self):
        import logging
        handler = self._makeOne()
        self.failUnless(isinstance(handler, logging.Handler))
    def test_emit_doesnt_raise_NotImplementedError(self):
        handler = self._makeOne()
        handler.emit(object())
class Test_make_api_factory_with_config(unittest.TestCase):
    _tempdir = None
    _warning_filters = None