summaryrefslogtreecommitdiff
path: root/oslo_log/helpers.py
diff options
context:
space:
mode:
authorDoug Hellmann <doug@doughellmann.com>2014-11-14 13:31:58 -0500
committerDavanum Srinivas <dims@linux.vnet.ibm.com>2014-12-17 21:43:41 -0500
commita5b9c2eccfa90d1c35a5c82e43a34cb766e1d651 (patch)
tree6b64be1143bfe81d60c88c82675cdb432bca7be3 /oslo_log/helpers.py
parentde9b26781ef0f8cf9408a22e6a77bc949bd21813 (diff)
downloadoslo-log-a5b9c2eccfa90d1c35a5c82e43a34cb766e1d651.tar.gz
Move files out of the namespace package
Move oslo.log to oslo_log. Since this library has not been released, we do not need to retain the old interface for compatibility. bp/drop-namespace-packages Change-Id: Id8e2312a72af171918fa4d40117ec652018a37bf
Diffstat (limited to 'oslo_log/helpers.py')
-rw-r--r--oslo_log/helpers.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/oslo_log/helpers.py b/oslo_log/helpers.py
new file mode 100644
index 0000000..9d6eaa7
--- /dev/null
+++ b/oslo_log/helpers.py
@@ -0,0 +1,47 @@
+# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+"""Log helper functions."""
+
+import functools
+import logging
+
+
+def _get_full_class_name(cls):
+ return '%s.%s' % (cls.__module__,
+ getattr(cls, '__qualname__', cls.__name__))
+
+
+def log_method_call(method):
+ """Decorator helping to log method calls.
+
+ The decorator is not intended to be used for static methods (which
+ are just simple functions from Python point of view).
+
+ :param method: Method to decorate to be logged.
+ :type method: method definition
+ """
+ log = logging.getLogger(method.__module__)
+
+ @functools.wraps(method)
+ def wrapper(*args, **kwargs):
+ first_arg = args[0]
+ cls = first_arg if isinstance(first_arg, type) else first_arg.__class__
+ data = {'class_name': _get_full_class_name(cls),
+ 'method_name': method.__name__,
+ 'args': args[1:], 'kwargs': kwargs}
+ log.debug('%(class_name)s method %(method_name)s '
+ 'called with arguments %(args)s %(kwargs)s', data)
+ return method(*args, **kwargs)
+ return wrapper