示例#1
0
 def test_proxies_log(self):
     """
     BoundLogger.exception.log() is proxied to the apropriate method.
     """
     bl = BoundLogger(ReturnLogger(), [return_method_name], {})
     assert "critical" == bl.log(50, "event")
     assert "debug" == bl.log(10, "event")
示例#2
0
 def test_exception_exc_info(self):
     """
     BoundLogger.exception sets exc_info=True.
     """
     bl = BoundLogger(ReturnLogger(), [], {})
     assert ((),
             {"exc_info": True, "event": "event"}) == bl.exception('event')
示例#3
0
    def test_proxies_exception(self):
        """
        BoundLogger.exception is proxied to Logger.error.
        """
        bl = BoundLogger(ReturnLogger(), [return_method_name], {})

        assert "error" == bl.exception("event")
示例#4
0
    def test_proxies_to_correct_method(self, method_name):
        """
        The basic proxied methods are proxied to the correct counterparts.
        """
        bl = BoundLogger(ReturnLogger(), [return_method_name], {})

        assert method_name == getattr(bl, method_name)("event")
示例#5
0
 def test_positional_args_proxied(self):
     """
     Positional arguments supplied are proxied as kwarg.
     """
     bl = BoundLogger(ReturnLogger(), [], {})
     args, kwargs = bl.debug('event', 'foo', bar='baz')
     assert 'baz' == kwargs.get('bar')
     assert ('foo',) == kwargs.get('positional_args')
示例#6
0
def build_bl(logger=None, processors=None, context=None):
    """
    Convenience function to build BoundLogger with sane defaults.
    """
    return BoundLogger(
        logger or ReturnLogger(),
        processors,
        {}
    )
示例#7
0
    def test_positional_args_proxied(self):
        """
        Positional arguments supplied are proxied as kwarg.
        """
        bl = BoundLogger(ReturnLogger(), [], {})
        args, kwargs = bl.debug("event", "foo", bar="baz")

        assert "baz" == kwargs.get("bar")
        assert ("foo", ) == kwargs.get("positional_args")
示例#8
0
    def test_exception_exc_info_override(self):
        """
        If *exc_info* is password to exception, it's used.
        """
        bl = BoundLogger(ReturnLogger(), [], {})

        assert ((), {"exc_info": 42, "event": "event"}) == bl.exception(
            "event", exc_info=42
        )
示例#9
0
    def test_stdlib_passthrough_attributes(self, attribute_name):
        """
        stdlib logger attributes are also available in stdlib BoundLogger.
        """
        stdlib_logger = logging.getLogger("Test")
        stdlib_logger_attribute = getattr(stdlib_logger, attribute_name)
        bl = BoundLogger(stdlib_logger, [], {})
        bound_logger_attribute = getattr(bl, attribute_name)

        assert bound_logger_attribute == stdlib_logger_attribute
示例#10
0
    def test_stdlib_passthrough_methods(self, method_name, method_args):
        """
        stdlib logger methods are also available in stdlib BoundLogger.
        """
        called_stdlib_method = [False]

        def validate(*args, **kw):
            called_stdlib_method[0] = True

        stdlib_logger = logging.getLogger('Test')
        stdlib_logger_method = getattr(stdlib_logger, method_name, None)
        if stdlib_logger_method:
            setattr(stdlib_logger, method_name, validate)
            bl = BoundLogger(stdlib_logger, [], {})
            bound_logger_method = getattr(bl, method_name)
            assert bound_logger_method is not None
            if method_args:
                bound_logger_method(*method_args)
            else:
                bound_logger_method()
            assert called_stdlib_method[0] is True
示例#11
0
 def test_exception_maps_to_error(self):
     bl = BoundLogger(ReturnLogger(), [return_method_name], {})
     assert "error" == bl.exception("event")