This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py.bak
84 lines (70 loc) · 2.81 KB
/
logger.py.bak
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
"""
IronicMTA Logger
"""
import logging
import colorama
import os
class Logger:
"""
Logger class\n
use it instead of 'print()'
"""
def __init__(self, log_file: str = "Logger.log") -> None:
colorama.init(autoreset=True)
self._localdir = __file__.split('\\')[:-1]
if self._localdir[0].endswith(':'):
self._localdir[0] += '\\'
self._localdir = os.path.join(*self._localdir)
logging.basicConfig(
filename=log_file, filemode='a', format='[%(asctime)s] %(levelname)s : %(message)s')
self._logger = logging.getLogger()
self._warn_format = logging.Formatter(
fmt=colorama.Fore.LIGHTBLACK_EX + '[%(asctime)s]' + colorama.Fore.YELLOW + '[%(levelname)s]: %(message)s')
self._error_format = logging.Formatter(
fmt=colorama.Fore.LIGHTBLACK_EX + '[%(asctime)s]' + colorama.Fore.RED + '[%(levelname)s]: %(message)s')
self._success_format = logging.Formatter(
fmt=colorama.Fore.LIGHTBLACK_EX + '[%(asctime)s]' + colorama.Fore.GREEN + '[%(levelname)s]: %(message)s')
self._log_format = logging.Formatter(
fmt=colorama.Fore.LIGHTBLACK_EX + '[%(asctime)s]' + colorama.Fore.LIGHTBLACK_EX + '[LOG]: %(message)s')
self._debug_format = logging.Formatter(
fmt=colorama.Fore.LIGHTBLACK_EX + '[%(asctime)s]' + colorama.Fore.BLUE + '[DEBUG]: %(message)s')
self._logger.setLevel(logging.DEBUG)
self._console_handler = logging.StreamHandler()
self._console_handler.setLevel(logging.DEBUG)
self._console_handler.setFormatter(self._log_format)
self._logger.addHandler(self._console_handler)
def log(self, message: str) -> None:
"""
Log Text
Color: White
"""
self._console_handler.setFormatter(self._log_format)
return self._logger.info(msg=message.strip())
def debug(self, message: str) -> None:
"""
Log Debug Text
Color: Blue
"""
self._console_handler.setFormatter(self._debug_format)
return self._logger.info(msg=message.strip())
def warn(self, message: str) -> None:
"""
Warn Log
Color: Yellow
"""
self._console_handler.setFormatter(self._warn_format)
return self._logger.warning(msg=message.strip())
def error(self, message: str) -> None:
"""
Error Log
Color: Red
"""
self._console_handler.setFormatter(self._error_format)
return self._logger.error(msg=message.strip())
def success(self, message: str) -> None:
"""
Sucess Log
Color: Green
"""
self._console_handler.setFormatter(self._success_format)
return self._logger.info(msg=message.strip())