-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_debugging.py
More file actions
63 lines (54 loc) · 1.03 KB
/
utils_debugging.py
File metadata and controls
63 lines (54 loc) · 1.03 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
import sys
import traceback
import datetime
"""
FOR DEBUGGING
"""
echo_path = "/etc/cloudns_sync/echo.log"
error_path = "/etc/cloudns_sync/error.log"
print_console = False
def SetEchoPath(ss):
global echo_path
echo_path = ss
def SetErrorPath(ss):
global error_path
error_path = ss
def SetPrintConsole(is_console):
global print_console
print_console = is_console
def Error(ss):
try:
global error_path
global print_console
if print_console:
print(ss)
else:
writer = open(error_path, "a")
print(ss, file=writer)
writer.close()
except:
pass
def Echo(ss, path=None):
try:
global echo_path
global print_console
if print_console:
print(ss)
else:
if path == None:
writer = open(error_path, "a")
else:
writer = open(path, "a")
print(ss, file=writer)
writer.close()
except:
pass
def Log(ss, path=None):
s = "[" + str(datetime.datetime.now()) + "]"
s += "\t"
s += ss
Echo(s, path)
def EchoTraceback():
t, v, tb = sys.exc_info()
result = traceback.format_exception(t,v,tb)
Echo(result)