-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebugableitem.py
More file actions
70 lines (60 loc) · 2.33 KB
/
Copy pathdebugableitem.py
File metadata and controls
70 lines (60 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#author : N.Pronk
#date : jan 2023
#licence: published under MIT licence
#
#Description
#--------------------------------------------------------------------
#class for debugging you program, especially when working with classes
#simply print the debug output to the console
#--------------------------------------------------------------------
#seealso: simpledebugger.py
#--------------------------------------------------------------------
#
#Usage
#--------------------------------------------------------------------
#Inherit your class from debugableitem and assign a class like
#simpledebugger
#
class DebugableItem():
"""
Description
--------------------------------------------------------------------
class for debugging you program, especially when working with classes
simply print the debug output to the console
--------------------------------------------------------------------
seealso: simpledebugger.py
--------------------------------------------------------------------
Usage
--------------------------------------------------------------------
Inherit your class from debugableitem and assign a class like
simpledebugger
Example
--------------------------------------------------------------------
class Myclass(DebugableItem):
x=1
def mymethod(self)
self.dbg_enter("mymethod()")
self.dbg_out("before assign",self.x)
x+=1
self.dbg_out("after assign",self.x)
self.dbg_leave("mymethod()")
myclassinstance=Myclass()
myclassinstance.debugger=SimpleDebugger()
myclassinstance.debug=True
"""
debug=False
debugger=None
def dbg_out(self, *args):
"""
print debuginfo to the console when the debug flag is on
"""
if self.debug==True and self.debugger!=None:
self.debugger.dbg_out(*args)
def dbg_enter(self, *args):
"""increase the 'trace' level and print debuginfo when the debug flag is on"""
if self.debug==True and self.debugger!=None:
self.debugger.dbg_enter(*args)
def dbg_leave(self, *args):
"""decrease the 'trace' level and print debuginfo when the debug flag is on"""
if self.debug==True and self.debugger!=None:
self.debugger.dbg_leave(*args)