-
Notifications
You must be signed in to change notification settings - Fork 3
/
logger.py
139 lines (119 loc) · 6.06 KB
/
logger.py
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import time
class Logger:
def __init__(self, debug_mode):
self.ui = None
self.debug_mode = debug_mode
self.span_end = "</style>"
def set_ui(self, ui):
self.ui = ui
def span_start(self, color):
return "<span style=\"color:" + color + ";\">"
def generate_timestamp(self):
localtime = time.localtime()
hour = localtime.tm_hour
if hour < 10:
hour = "0" + str(hour)
minute = localtime.tm_min
if minute < 10:
minute = "0" + str(minute)
second = localtime.tm_sec
if second < 10:
second = "0" + str(second)
timestamp = "%s:%s:%s" % (hour, minute, second)
return timestamp
def join_message(self, msg, param):
msg_join = msg + " %s" % param
return msg_join
def warning(self, message, param = None):
if param != None:
message = self.join_message(message, param)
timestamp = self.generate_timestamp()
post_timestamp = " "
category = "[WARNING]:"
html_message = timestamp + post_timestamp + self.span_start("#cdbc2a") + category + " " + message + self.span_end
self.log(html_message, timestamp, post_timestamp, category, message)
def error(self, message, param = None):
if param != None:
message = self.join_message(message, param)
timestamp = self.generate_timestamp()
post_timestamp = " --"
category = "[ERROR]:"
html_message = timestamp + self.span_start("white") + post_timestamp + self.span_end + self.span_start("red") + category + " " + message + self.span_end
self.log(html_message, timestamp, post_timestamp, category, message)
def info(self, message, param = None):
if param != None:
message = self.join_message(message, param)
timestamp = self.generate_timestamp()
post_timestamp = " ---"
category = "[INFO]:"
html_message = timestamp + self.span_start("white") + post_timestamp + self.span_end + self.span_start("black") + category + " " + message + self.span_end
self.log(html_message, timestamp, post_timestamp, category, message)
def auth(self, message, param = None):
if param != None:
message = self.join_message(message, param)
timestamp = self.generate_timestamp()
post_timestamp = " ---"
category = "[AUTH]:"
html_message = timestamp + self.span_start("white") + post_timestamp + self.span_end + self.span_start("green") + category + " " + message + self.span_end
self.log(html_message, timestamp, post_timestamp, category, message)
def config(self, message, param = None):
if param != None:
message = self.join_message(message, param)
timestamp = self.generate_timestamp()
post_timestamp = " -"
category = "[CONFIG]:"
html_message = timestamp + self.span_start("white") + post_timestamp + self.span_end + self.span_start("purple") + category + " " + message + self.span_end
self.log(html_message, timestamp, post_timestamp, category, message)
def network(self, message, param = None):
if param != None:
message = self.join_message(message, param)
timestamp = self.generate_timestamp()
post_timestamp = " "
category = "[NETWORK]:"
html_message = timestamp + post_timestamp + self.span_start("blue") + category + " " + message + self.span_end
self.log(html_message, timestamp, post_timestamp, category, message)
def network_error(self, message, param = None):
if param != None:
message = self.join_message(message, param)
timestamp = self.generate_timestamp()
post_timestamp = " "
category = "[NETWORK ERROR]:"
html_message = timestamp + post_timestamp + self.span_start("red") + category + " " + message + self.span_end
self.log(html_message, timestamp, post_timestamp, category, message)
def sync(self, message, param = None):
if param != None:
message = self.join_message(message, param)
timestamp = self.generate_timestamp()
post_timestamp = " ---"
category = "[SYNC]:"
html_message = timestamp + self.span_start("white") + post_timestamp + self.span_end + self.span_start("blue") + category + " " + message + self.span_end
self.log(html_message, timestamp, post_timestamp, category, message)
def sync_error(self, message, param = None):
if param != None:
message = self.join_message(message, param)
timestamp = self.generate_timestamp()
post_timestamp = " "
category = "[SYNC ERROR]:"
html_message = timestamp + post_timestamp + self.span_start("red") + category + " " + message + self.span_end
self.log(html_message, timestamp, post_timestamp, category, message)
def transfer(self, message, param = None):
if param != None:
message = self.join_message(message, param)
timestamp = self.generate_timestamp()
post_timestamp = " "
category = "[TRANSFER]:"
html_message = timestamp + post_timestamp + self.span_start("blue") + category + " " + message + self.span_end
self.log(html_message, timestamp, post_timestamp, category, message)
def transfer_error(self, message, param = None):
if param != None:
message = self.join_message(message, param)
timestamp = self.generate_timestamp()
post_timestamp = " "
category = "[TRANSFER ERROR]:"
html_message = timestamp + post_timestamp + self.span_start("red") + category + " " + message + self.span_end
self.log(html_message, timestamp, post_timestamp, category, message)
def log(self, html_message, timestamp, post_timestamp, category, message):
if self.ui != None:
self.ui.console_ui.text_area.appendHtml(html_message)
if self.debug_mode:
print "%s%s%s %s" % (timestamp, post_timestamp, category, message)