-
Notifications
You must be signed in to change notification settings - Fork 6
/
my_logging.py
41 lines (32 loc) · 1.46 KB
/
my_logging.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
import time
import sys
from termcolor import colored
class Log(object):
def __init__(self, folder):
self.log_folder = folder + "logfile.log"
def info(self,message):
msg_type = "INFO"
data = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime())
print(colored(f"{data} [{msg_type}] - {message}", "white"))
with open(self.log_folder, "a+") as out:
out.write(f"{data} [{msg_type}] - {message}\n")
def error(self,message):
msg_type = "ERROR"
data = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime())
print(colored(f"{data} [{msg_type}] - {message}", "red"))
with open(self.log_folder, "a+") as out:
out.write(f"{data} [{msg_type}] - {message}\n")
def debug(self,message):
gettrace = getattr(sys, 'gettrace', None)
msg_type = "DEBUG"
data = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime())
if gettrace is not None and gettrace():
print(colored(f"{data} [{msg_type}] - {message}", "green"))
with open(self.log_folder, "a+") as out:
out.write(f"{data} [{msg_type}] - {message}\n")
def important(self,message):
msg_type = "INFO"
data = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime())
print(colored(f"{data} [{msg_type}] - {message}", "cyan"))
with open(self.log_folder, "a+") as out:
out.write(f"{data} [{msg_type}] - {message}\n")