aspectlib.debug.log | Decorates func to have logging. |
aspectlib.debug.format_stack | Returns a one-line string with the current callstack. |
aspectlib.debug.frame_iterator | Yields frames till there are no more. |
aspectlib.debug.strip_non_ascii | Convert to string (using str) and replace non-ascii characters with a dot (.). |
Returns a one-line string with the current callstack.
Convert to string (using str) and replace non-ascii characters with a dot (.).
Decorates func to have logging.
Parameters: |
|
---|---|
Returns: | A decorator or a wrapper. |
Example:
>>> @log(print_to=sys.stdout)
... def a(weird=False):
... if weird:
... raise RuntimeError('BOOM!')
>>> a()
a() <<< ...
a => None
>>> try:
... a(weird=True)
... except Exception:
... pass # naughty code !
a(weird=True) <<< ...
a ~ raised RuntimeError('BOOM!',)
You can conveniently use this to logs just errors, or just results, example:
>>> import aspectlib
>>> with aspectlib.weave(int, log(call=False, result=False, print_to=sys.stdout)):
... try:
... int('invalid')
... except Exception:
... pass # naughty code !
int('invalid') <<< ...
int ~ raised ValueError("invalid literal for int() with base 10: 'invalid'",)
This makes debugging naughty code easier.
Changed in version 0.5.0: Renamed arguments to call_args. Renamed arguments_repr to call_args_repr. Added call option.