summaryrefslogtreecommitdiffstats
path: root/src/python
diff options
context:
space:
mode:
Diffstat (limited to 'src/python')
-rw-r--r--src/python/lmi/providers/cmpi_logging.py28
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.