-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathlogger.py
69 lines (55 loc) · 1.84 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
import logging
from utils.colors import Color
class Logger:
def __init__(self, obj):
"""
Logger to log errors and other messages
:param obj: Obj (automatically gets type name) or name as a string.
:type obj: str or obj
:raise TypeError: If string or obj different
"""
self.__class_name = None
self.set_class_name(obj)
def set_class_name(self, obj):
"""
Set the class name.
:param obj: Obj (automatically gets type name) or name as a string.
:type obj: str or obj
:raise TypeError: If string or obj different
"""
if isinstance(obj, str):
self.__class_name = obj
elif isinstance(obj, object):
self.__class_name = object.__class__.__name__
else:
raise TypeError(
f"Obj is of type {type(obj)}, the required type is 'str' or 'object'"
)
def debug(self, string: str):
"""
Prints debug message.
:param string: The string message.
:type string: str
"""
logging.debug(f"[{self.__class_name}] {string}")
def warning(self, string: str):
"""
Prints warn message.
:param string: The string message.
:type string: str
"""
logging.warning(f"{Color.WARNING}[{self.__class_name}] {string}{Color.ENDC}")
def info(self, string: str):
"""
Prints info message.
:param string: The string message.
:type string: str
"""
logging.info(f"{Color.CGREEN}[{self.__class_name}] {string}{Color.ENDC}")
def error(self, string: str):
"""
Prints error message.
:param string: The string message.
:type string: str
"""
logging.error(f"{Color.FAIL}[{self.__class_name}] {string}{Color.ENDC}")