benchmarkstt.decorators module¶
-
benchmarkstt.decorators.
log_call
(logger: logging.Logger, log_level=None, result=None)[source]¶ Decorator to log all calls to decorated function to given logger
>>> import logging, sys, io >>> >>> logger = logging.getLogger('logger_name') >>> logger.setLevel(logging.DEBUG) >>> ch = logging.StreamHandler(sys.stdout) >>> ch.setFormatter(logging.Formatter('%(levelname)s:%(name)s: %(message)s')) >>> logger.addHandler(ch) >>> >>> @log_call(logger, logging.WARNING) ... def test(*args, **kwargs): ... return 'result' >>> test('arg1', arg2='someval', arg3='someotherval') WARNING:logger_name: test('arg1', arg2='someval', arg3='someotherval') 'result' >>> @log_call(logger, result=True) ... def test(*args, **kwargs): ... return 'result' >>> test(arg2='someval', arg3='someotherval') DEBUG:logger_name: test(arg2='someval', arg3='someotherval') DEBUG:logger_name: test returned: result 'result'