-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlog.py
36 lines (30 loc) · 1.22 KB
/
log.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
import logging
from pathlib import Path
from time import strftime
class Log:
def __init__(self, level):
subPath = "./logs"
Path("./logs").mkdir(parents=True, exist_ok=True)
filename="%s/autotune_%s.log" % (subPath, strftime("%Y-%m-%d_%H_%M_%S"))
if level == "INFO":
logging.basicConfig(filename=filename, level=logging.INFO)
elif level == "WARNING":
logging.basicConfig(filename=filename, level=logging.WARNING)
elif level == "ERROR":
logging.basicConfig(filename=filename, level=logging.ERROR)
else:
logging.basicConfig(filename=filename, level=logging.DEBUG)
def GetMessage(self, msg):
return strftime("%Y-%m-%d %H:%M:%S") + " - " + msg
def Error(self, msg):
logging.error(self.GetMessage(msg))
print("ERR:\t%s" % self.GetMessage(msg))
def Warning(self, msg):
logging.warning(self.GetMessage(msg))
print("WARN:\t%s" % self.GetMessage(msg))
def Info(self, msg):
logging.info(self.GetMessage(msg))
print("INFO:\t%s" % self.GetMessage(msg))
def Debug(self, msg):
logging.debug(self.GetMessage(msg))
print("DEBUG:\t%s" % self.GetMessage(msg))