This module contains a Metlog decorator base class and some additional helper code. The primary reason for these abstractions is ‘deferred configuration’. Decorators are evaluated by Python at import time, but often the configuration needed for a Metlog client, which might negate (or change) the behavior of a Metlog decorator, isn’t available until later, after some config parsing code has executed. This code provides a mechanism to have a function get wrapped in one way (or not at all) when the decorator is originally evaluated, but then to be wrapped differently once the config has loaded and the desired final behavior has been established.
This is a base class for Metlog decorators, designed to support ‘rebinding’ of the actual decorator method once Metlog configuration has actually been loaded. The first time the decorated function is invoked, the predicate method will be called. If the result is True, then metlog_call (intended to be implemented by subclasses) will be used as the decorator. If the predicate returns False, then _invoke (which by default does nothing but call the wrapped function) will be used as the decorator.