open-things / loggingex

Extensions for the standard logging module.
MIT License
2 stars 4 forks source link

Make decorator more useful #5

Open Paulius-Maruska opened 5 years ago

Paulius-Maruska commented 5 years ago

This is related to #4.

Currently, be because the values are all static - context as decorator is rather useless. Once #4 is implemented, add some special helpers for automatically adding information about the decorated function and what arguments were passed to it at runtime.

With this feature, something like this, should become possible:

from loggingex.context import context, argument

@context(foo_args=argument(arg=True))
def foo(*args):
    return sum(args)

@context(bar_name=argument("name"), bar_message=argument(arg=0, kwarg="message"))
def bar(message, *, name="default"):
    print("%s: %s" % (name, message))

Note: When used as context manager, these argument values would be ignored (or some default values would need to be returned for them).