-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlog.py
33 lines (27 loc) · 855 Bytes
/
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
import logging
import os
class Logger:
@classmethod
def get_logger(cls, filepath=None, log_level=logging.INFO):
if filepath is None:
filepath = os.path.join(os.path.dirname(__file__), "log.txt")
logging.basicConfig(
level=log_level,
filename=filepath,
filemode="a",
format="[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]: %(message)s",
encoding="utf-8",
)
return logging.getLogger()
@classmethod
def debug(cls, msg):
cls.get_logger().debug(msg)
@classmethod
def info(cls, msg):
cls.get_logger().info(msg)
@classmethod
def warning(cls, msg):
cls.get_logger().warning(msg)
@classmethod
def error(cls, msg):
cls.get_logger().error(msg)