diff options
author | Michal Minar <miminar@redhat.com> | 2013-10-10 15:01:57 +0200 |
---|---|---|
committer | Michal Minar <miminar@redhat.com> | 2013-10-10 15:43:09 +0200 |
commit | 0063553e0f3f89f3c5ec6f6c8b8d080296138ccd (patch) | |
tree | 4da7edb65fd615aadf2125f2b670d569fd420074 | |
parent | 6825842ab33c4eae5f82ea18f684417cab641b9d (diff) | |
download | openlmi-providers-0063553e0f3f89f3c5ec6f6c8b8d080296138ccd.tar.gz openlmi-providers-0063553e0f3f89f3c5ec6f6c8b8d080296138ccd.tar.xz openlmi-providers-0063553e0f3f89f3c5ec6f6c8b8d080296138ccd.zip |
python: allow to disable tracing decorators
Tracing decorators are everywhere and they make debugging very
inconvenient. This allows to disable them easily using environment
variable.
To disable them, just add
export LMI_DISABLE_TRACING_DECORATORS=1
to your
/usr/libexec/pegasus/$provider-cimprovagt
script.
-rw-r--r-- | src/python/lmi/providers/cmpi_logging.py | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/python/lmi/providers/cmpi_logging.py b/src/python/lmi/providers/cmpi_logging.py index 1199401..4fc5df2 100644 --- a/src/python/lmi/providers/cmpi_logging.py +++ b/src/python/lmi/providers/cmpi_logging.py @@ -194,7 +194,7 @@ def render_value(val): ", " if len(val) < 2 else '') return repr(val) -def trace_function_or_method(is_method=False, frame_level=1): +def _trace_function_or_method(is_method=False, frame_level=1): """ Factory for function and method decorators. Generated decorators log every calls and exits of decorated functions or methods. @@ -202,10 +202,10 @@ def trace_function_or_method(is_method=False, frame_level=1): Logged information contain the caller's module and line together with called function's module, function name and line number. - :param is_method: (``bool``) Whether returned decorator is targeted + :param boolean is_method: Whether returned decorator is targeted for use upon a method of a class. It modified logged function by prepending owning class name. - :param frame_level: (``int``) Number of nested frames to skip when + :param integer frame_level: Number of nested frames to skip when searching for called function scope by inspecting stack upwards. When the result of this function is applied directly on the definition of function, it's value should be 1. When used from inside of some @@ -280,14 +280,32 @@ def trace_function_or_method(is_method=False, frame_level=1): return _decorator -def trace_function(func, frame_level=1): +def _trace_function(func, frame_level=1): """ Convenience function used for decorating simple functions. """ return trace_function_or_method(frame_level=frame_level + 1)(func) -def trace_method(func, frame_level=1): +def _trace_method(func, frame_level=1): """ Convenience function used for decorating methods. """ return trace_function_or_method(True, frame_level + 1)(func) +def _identity_decorator(func, *args, **kwargs): + """ Decorator returning the function itself. """ + return func + +# Tracing decorators may be disabled by environment variable. +if os.getenv("LMI_DISABLE_TRACING_DECORATORS", "0").lower() in \ + ("1", "true", "yes", "on"): + # Tracing decators disabled. Functions and method won't get modified + # in any way. + trace_function_or_method = _identity_decorator + trace_function = _identity_decorator + trace_method = _identity_decorator +else: + # Tracing decorators enabled. + trace_function_or_method = _trace_function_or_method + trace_function = _trace_function + trace_method = _trace_method + def try_setup_from_file(config): """ Try to configure logging with a file specified in configuration. |