Bug 43422 - turn univention.debug.function into decorator
turn univention.debug.function into decorator
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: univention-debug
UCS 4.4
Other Linux
: P5 normal (vote)
: UCS 4.4-0-errata
Assigned To: Philipp Hahn
Florian Best
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2017-01-25 16:59 CET by Florian Best
Modified: 2019-05-29 13:24 CEST (History)
2 users (show)

See Also:
What kind of report is it?: Development Internal
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional): API change, Error handling, Further conceptual development, Usability
Max CVSS v3 score:


Attachments
patch / script (1.14 KB, text/x-python)
2017-01-26 14:57 CET, Florian Best
Details
Add univention.debug decorator (4.04 KB, patch)
2018-11-13 15:58 CET, Philipp Hahn
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Best univentionstaff 2017-01-25 16:59:44 CET
@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.
Comment 1 Florian Best univentionstaff 2017-01-25 17:12:10 CET
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
Comment 2 Arvid Requate univentionstaff 2017-01-25 19:12:56 CET
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.
Comment 3 Florian Best univentionstaff 2017-01-26 14:57:40 CET
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
Comment 4 Philipp Hahn univentionstaff 2018-11-13 15:58:35 CET
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.
Comment 5 Philipp Hahn univentionstaff 2019-05-07 12:10:54 CEST
Updated patch is part of my git:phahn/46100_debug2 tree:
https://git.knut.univention.de/univention/ucs/commit/87e7efc024ba21965f95249f60d46e31ea69da30
Comment 6 Philipp Hahn univentionstaff 2019-05-20 13:54:00 CEST
[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.
Comment 7 Florian Best univentionstaff 2019-05-20 18:03:26 CEST
OK: YAML
OK: decorator
OK: no warning is printed when using the old ud.function().
Comment 8 Arvid Requate univentionstaff 2019-05-29 13:24:08 CEST
<http://errata.software-univention.de/ucs/4.4/120.html>