def test_log_level(self):
        
        with log.message_logging(self.request, __name__, logging.ERROR):
            self.logger.error('oops')
            self.logger.debug('niggling details')

        self.assertEqual(1, len(mock_messages),
            'There should be only 1 log messages (level filter), got %d' % \
            len(mock_messages))
    def test_override_level(self):
        self.logger.setLevel(logging.CRITICAL)

        with log.message_logging(self.request, __name__, logging.DEBUG):
            self.logger.info("here's the scoop")

        self.assertEqual(1, len(mock_messages),
            'There should be one 1 log message (log level higher than requested message logging), got %d' \
            % len(mock_messages))            
        self.assertEqual(logging.CRITICAL, self.logger.getEffectiveLevel(),
            'log level is set to same level as it was before using context manager')
    def test_logname(self):
        otherlogger = logging.getLogger('my.other.logger')
        otherlogger.setLevel(logging.DEBUG)
        otherlogger.addHandler(NullHandler())

        with log.message_logging(self.request, 'my.other.logger', logging.DEBUG):
            self.logger.error('main log error')
            otherlogger.error('other log error')

        self.assertEqual(1, len(mock_messages),
            'There should be only 1 log messages (filter by log name), got %d' \
            % len(mock_messages))
    def test_basic_functionality(self):
        with log.message_logging(self.request, __name__, logging.DEBUG):
            self.logger.critical('criticize this')
            self.logger.debug('rebug')
            self.logger.info('fyi')

        # after context - this should *not* be converted to a message
        self.logger.error('pick me! pick me!')
        
        self.assertEqual(3, len(mock_messages),
            'There should be 3 log messages (3 in context, 1 outside), got %d' % len(mock_messages))
        self.assertEqual('criticize this', mock_messages[0][1])
        self.assertEqual('rebug', mock_messages[1][1])
        self.assertEqual('fyi', mock_messages[2][1])