Univention Bugzilla – Bug 43422
turn univention.debug.function into decorator
Last modified: 2019-05-29 13:24:08 CEST
@Arvid, here for you :) You need to vote! Currently one needs to: def func(some_args): _d = univention.debug.function('func() with args %r' % some_args) pass This could be changed into: @univention.debug.function(with_arguments=True, with_return_value=True) def func(some_args): pass Function name would be automatically be logged, as well as arguments if you want so.
It would also fix these stupid messages which slow down every time I want to commit something: management/univention-directory-manager-modules/modules/univention/admin/handlers/__init__.py:267: local variable '_d' is assigned to but never used management/univention-directory-manager-modules/modules/univention/admin/handlers/__init__.py:1057: local variable '_d' is assigned to but never used management/univention-directory-manager-modules/modules/univention/admin/handlers/__init__.py:2729: local variable '_d' is assigned to but never used
It would also be nice to let the decorator make something like '__ucs_func_name' available, so it can be used easily in debug messages.
Created attachment 8377 [details] patch / script Running the scripts gives e.g. this output: 26.01.17 14:57:23.642 DEBUG_INIT UNIVENTION_DEBUG_BEGIN : foo UNIVENTION_DEBUG_END : foo UNIVENTION_DEBUG_BEGIN : __main__.bar(('x', 'y', 'z'), {'blub': 1}) UNIVENTION_DEBUG_END : __main__.bar(('x', 'y', 'z'), {'blub': 1}) UNIVENTION_DEBUG_BEGIN : __main__.Baz.baz() UNIVENTION_DEBUG_END : __main__.Baz.baz() -> 1
Created attachment 9743 [details] Add univention.debug decorator Also log exception. Make output format for parameters and return values configurabel: str, repr, ... Add Sphinx DocString.
Updated patch is part of my git:phahn/46100_debug2 tree: https://git.knut.univention.de/univention/ucs/commit/87e7efc024ba21965f95249f60d46e31ea69da30
[4.4-0] d57be2fe6c Bug #43422 debug.py: logging function decorator Package: univention-debug-python Version: 1.0.0-1A~4.4.0.201905201332 Branch: ucs_4.4-0 Scope: errata4.4-0 [4.4-0] f78f7c4d55 Bug #49130: univention-debug 11.0.0-2A~4.4.0.201905171721 Bug #49130: univention-debug-python 1.0.0-1A~4.4.0.201905201308 doc/errata/staging/univention-debug-python.yaml | 13 +++++++++++++ doc/errata/staging/univention-debug.yaml | 11 +++++++++++ doc/errata/staging/univention-python.yaml | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) Introduce decorator "@univention.debug.trace()" to start deprecating "function" together with the transition from "python-support" to "pybuild" and to "Python3". See Bug #48893 for some un-fix(ed|able) issues.
OK: YAML OK: decorator OK: no warning is printed when using the old ud.function().
<http://errata.software-univention.de/ucs/4.4/120.html>