open-things / loggingex

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

Support for dynamic values #4

Open Paulius-Maruska opened 5 years ago

Paulius-Maruska commented 5 years ago

Currently only static values are supported - whatever keyword argument values you pass to context, that's what you're going to get added to the log records. This is good for a lot of cases, but not perfect for some others. One inconvenience with this, is that you have to reset the context each time a value changes.

Implement a dynamic value feature, so that it was possible to do something like this:

from loggingex.context import context, value

GLOBAL_VALUE = "initial value"

def value_lookup():
    return GLOBAL_VALUE

with context(global_value=value(lookup=value_lookup)):
    # some code that logs stuff
    GLOBAL_VALUE = "different value"
    # some code that logs stuff
    pass