-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.py
More file actions
71 lines (62 loc) · 2.11 KB
/
helper.py
File metadata and controls
71 lines (62 loc) · 2.11 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
71
from colorama import Fore, Back, Style
class Logger(object):
"""docstring for Logger."""
__is_logging__ = False
types = {
0: Back.LIGHTBLUE_EX, # Origin (i.e. TAG) Color
1: Fore.WHITE, # Info (i.e. Logger.info) Color
2: Fore.GREEN, # Debug (i.e. Logger.debug) Color
3: Fore.YELLOW, # Warn (i.e. Logger.warn) Color
4: Fore.LIGHTRED_EX, # Error (i.e. Logger.error) Color
5: Fore.RED # Critical Error (i.e. Logger.critical) Color
}
__reset__ = Style.RESET_ALL
def __init__(self):
super(Logger, self).__init__()
@classmethod
def switch_logging(self, flag = None):
self.__is_logging__ = (not self.__is_logging__) if flag == None else flag
@classmethod
def color(self, message, type):
return '{}{}{}'.format(
self.types[type],
message,
self.__reset__
)
@classmethod
def info(self, TAG, message):
if(self.__is_logging__):
print('{} {}'.format(
self.color('[ {} ]::'.format(TAG), 0),
self.color(message, 1)
))
@classmethod
def debug(self, TAG, message):
if(self.__is_logging__):
print('{} {}'.format(
self.color('[ {} ]::'.format(TAG), 0),
self.color(message, 2)
))
@classmethod
def warn(self, TAG, message):
if(self.__is_logging__):
print('{} {}'.format(
self.color('[ {} ]::'.format(TAG), 0),
self.color(message, 3)
))
@classmethod
def error(self, TAG, message, err = None):
if(self.__is_logging__):
print('{} {}\n {}'.format(
self.color('[ {} ]::'.format(TAG), 0),
self.color(message, 4),
self.color(err, 4)
))
@classmethod
def critical(self, TAG, message, err = None):
if(self.__is_logging__):
print('{} {}\n {}'.format(
self.color('[ {} ]::'.format(TAG), 0),
self.color(message, 5),
self.color(err, 5)
))