Exemplo n.º 1
0
 def wrapper(*args, **kwargs):
     try:
         a = [str(x)[:255] for x in args]
         kw = dict([(k[:255], str(v)[:255]) for k, v in kwargs.items()])
         log.trace('Calling %s.%s %r %r', fn.__module__, fn.__name__, a, kw)
         return fn(*args, **kwargs)
     except Exception as e:
         log.error('Error calling function %s: %s' % (fn.__name__, e))
         log.exception(e)
         raise
Exemplo n.º 2
0
def test_eager_formatting_adapter(log_stream):
    log = AutoLogger(EagerFormattingAdapter)
    log.log(0, 'suppressed')
    log.debug('a %(a)d b %(b)s', {'a': 1, 'b': 2})
    log.trace('TEST NO INTERPOLATION')
    log.trace('TEST %s', 'MSG')
    log.debug('TEST %s', 'MSG')
    log.info('TEST %s%s%s', 'M', 'S', 'G')
    log.warn('TEST %s', 'MSG')
    log.warning('TEST %s', 'MSG')
    log.error('TEST %s', 'MSG')
    try:
        assert False
    except Exception:
        log.exception('TEST %s', 'MSG')
    log.critical('TEST %s', 'MSG')
    log.fatal('TEST %s', 'MSG')
    result = log_stream.getvalue()

    assert result.startswith("""\
[DEBUG] tests.test_logging: a 1 b 2
[TRACE] tests.test_logging: TEST NO INTERPOLATION
[TRACE] tests.test_logging: TEST MSG
[DEBUG] tests.test_logging: TEST MSG
[INFO] tests.test_logging: TEST MSG
[WARNING] tests.test_logging: TEST MSG
[WARNING] tests.test_logging: TEST MSG
[ERROR] tests.test_logging: TEST MSG
[ERROR] tests.test_logging: TEST MSG
  Traceback (most recent call last):
""")

    assert result.endswith("""\
  AssertionError: assert False
[CRITICAL] tests.test_logging: TEST MSG
[CRITICAL] tests.test_logging: TEST MSG
""")
Exemplo n.º 3
0
 def test_autolog_from_class(self, log_stream):
     from pockets.autolog import log
     log.trace('TEST MSG')
     assert log_stream.getvalue() == \
         '[TRACE] tests.test_logging.TestAutoLogFromClass: TEST MSG\n'
Exemplo n.º 4
0
def test_autolog_from_function(log_stream):
    from pockets.autolog import log
    log.trace('TEST MSG')
    assert log_stream.getvalue() == '[TRACE] tests.test_logging: TEST MSG\n'