-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconsole.py
130 lines (98 loc) · 3.4 KB
/
console.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
from datetime import datetime as dt
import platform
from termcolor import colored
# Old features
TAGS = {
'error': colored("[ ERR ]", color="white", on_color="on_red"),
'log': colored("[ LOG ]", attrs=['reverse']),
'info': colored("[ INFO ]", color="grey", on_color="on_yellow"),
'success': colored("[SUCCESS]", color="white", on_color="on_green")
}
if platform.system() == 'Windows':
TAGS = {
'error': "[ ERR ]",
'log': "[ LOG ]",
'info': "[ INFO ]",
'success': "[SUCCESS]"
}
def __timestamp__():
return "[%d:%d:%d:%d]" % (dt.now().time().hour, dt.now().time().minute, dt.now().time().second, dt.now().time().microsecond)
def __print__(tag="", msg=""):
print("%s%s : %s" % (__timestamp__(), tag, msg))
def error(msg):
__print__(tag=TAGS['error'], msg=msg)
def log(msg):
__print__(tag=TAGS['log'], msg=msg)
def info(msg):
__print__(tag=TAGS['info'], msg=msg)
def success(msg):
__print__(tag=TAGS['success'], msg=msg)
# New features
class Console:
TAGS = {
'error': colored("[ ERR ]", color="white", on_color="on_red"),
'log': colored("[ LOG ]", attrs=['reverse']),
'info': colored("[ INFO ]", color="grey", on_color="on_yellow"),
'success': colored("[SUCCESS]", color="white", on_color="on_green")
}
VERBOSITY = 4
SHOW_TIME = True
def __init__(self):
if platform.system() == 'Windows':
self.monotone()
def __timestamp__(self):
if self.SHOW_TIME:
return "[%d:%d:%d:%d]" % (dt.now().time().hour, dt.now().time().minute, dt.now().time().second, dt.now().time().microsecond)
else:
return ""
@classmethod
def __please__(self):
1 + 1
return
def __print__(self, tag="", msg=""):
print("%s%s : %s" % (self.__timestamp__(), tag, msg))
def mute(self):
self.VERBOSITY = 0
def monotone(self):
self.TAGS = {
'error': "[ ERR ]",
'log': "[ LOG ]",
'info': "[ INFO ]",
'success': "[SUCCESS]"
}
def timeless(self):
self.SHOW_TIME = False
def setVerbosity(self, level):
if level > 5:
level = 5
elif level < 0:
level = 0
self.VERBOSITY = level
def __should_i_shutup__(self, l):
return l > self.VERBOSITY
def error(self, msg):
if self.__should_i_shutup__(1):
return
self.__print__(tag=self.TAGS['error'], msg=msg)
self.__please__()
def log(self, msg):
if self.__should_i_shutup__(3):
return
self.__print__(tag=self.TAGS['log'], msg=msg)
self.__please__()
def info(self, msg):
if self.__should_i_shutup__(4):
return
self.__print__(tag=self.TAGS['info'], msg=msg)
self.__please__()
def success(self, msg):
if self.__should_i_shutup__(2):
return
self.__print__(tag=self.TAGS['success'], msg=msg)
self.__please__()
def secure(self, tag, msg):
if self.__should_i_shutup__(5):
return
self.__print__(tag=colored(tag, color="white",
on_color="on_blue"), msg=msg)
self.__please__()