-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
118 lines (88 loc) · 4.76 KB
/
README
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
log traceback information in a readable way
===========================================
write_func - a function used to write exceptions, receieves string
add_newline - if True, adds a newline to every line passed to write_func
Magic Variables:
----------------
If you define one of these variables in your local scope, you can add information
to tracebacks that happen in that context. This allows applications to add all sorts
of extra information about the context of the error
``__traceback_hide__``:
If set and true, this indicates that the frame should be hidden from abbreviated tracebacks.
(the frame won't be logged) This allows to hide some of the complexety of the traceback and
let the user focus on the relevant path
``__traceback_hide_all_vars__``:
If set and true, this indicates that all the vars in this context should be hidden (in order to avoid
leak of information)
``__traceback_hide_vars__``:
[variable which supports "in"] if set, variable names in __traceback_hide_vars__ aren't logged.
``__traceback_expand_vars__``:
[variable which supports "in"] if set, variable names in __traceback_expand_vars__ are expanded (otherwise, only the first 40 chars are displayed).
``__traceback_stop__``:
If set and true, stop traversing traceback in lower levels
``__traceback_stop_display_vars__``:
If set and true, stop traversing displaying variables in lower levels
``__traceback_start__``:
If set and true, start up the traceback again, if ``__traceback_stop__`` has come into play
``__traceback_start_display_vars__``:
If set and true, start up displaying variables again, if ``__traceback_stop_display_vars__`` has come into play
Example
-------
from log_exception import log_exception
import sys
def login(username, password, reason):
__traceback_hide_vars__ = ['password']
__traceback_expand_vars__ = ['reason']
#do_login doesn't exist, and will cause an exception
do_login(username, password)
def play(username, password):
__traceback_hide_vars__ = ['password']
reason = "I just want to login, will you help me good sir?"
login(username, password, reason)
def run(username, password):
try:
play(username, password)
except Exception, e:
log_exception(write_func = sys.stderr.write , add_newline = True)
if __name__ == '__main__':
run('admin', 'Sekret')
Output:
-------
File: 'example.py', line number: 19
login(username, password, reason)
def run(username, password):
try:
--> play(username, password)
except Exception, e:
log_exception(write_func = sys.stderr.write , add_newline = True)
NameError: global name 'do_login' is not defined
Variable Type Value
-------- ---- -----
e NameError global name 'do_login' is not defined
password str Sekret
username str admin
File: 'example.py', line number: 15
def play(username, password):
__traceback_hide_vars__ = ['password']
reason = "I just want to login, will you help me good sir?"
--> login(username, password, reason)
def run(username, password):
try:
NameError: global name 'do_login' is not defined
Variable Type Value
-------- ---- -----
password str [hidden]
reason str I just want to login, will you help me g
username str admin
File: 'example.py', line number: 9
__traceback_hide_vars__ = ['password']
__traceback_expand_vars__ = ['reason']
#do_login doesn't exist, and will cause an exception
--> do_login(username, password)
def play(username, password):
NameError: global name 'do_login' is not defined
Variable Type Value
-------- ---- -----
password str [hidden]
reason str I just want to login, will you help me good sir?
username str admin