2023-03-27 19:40:52 -07:00
|
|
|
|
|
|
|
import logging
|
2023-03-27 19:59:45 -07:00
|
|
|
import sys
|
2023-03-27 19:40:52 -07:00
|
|
|
|
|
|
|
class Logger:
|
|
|
|
|
2023-03-27 19:59:45 -07:00
|
|
|
def __init__(self, name: str, debug: bool=False):
|
2023-03-27 19:40:52 -07:00
|
|
|
|
|
|
|
self.__name = name
|
2023-03-27 19:59:45 -07:00
|
|
|
|
|
|
|
self.__logger = logging.getLogger(self.__name)
|
2023-03-27 19:40:52 -07:00
|
|
|
|
2023-03-27 19:59:45 -07:00
|
|
|
if debug:
|
|
|
|
level = logging.DEBUG
|
|
|
|
else:
|
|
|
|
level = logging.INFO
|
|
|
|
|
|
|
|
self.__logger.setLevel(level)
|
|
|
|
|
|
|
|
formatter = logging.Formatter('[%(asctime)s][%(name)s][%(levelname)s] %(message)s')
|
|
|
|
|
|
|
|
# Console output / stream handler
|
|
|
|
handler = logging.StreamHandler()
|
|
|
|
handler.setLevel(level)
|
|
|
|
handler.setFormatter(formatter)
|
|
|
|
self.__logger.addHandler(handler)
|
|
|
|
|
2023-03-27 19:40:52 -07:00
|
|
|
def debug(self, s):
|
2023-03-27 19:59:45 -07:00
|
|
|
self.__logger.debug(s)
|
2023-03-27 19:40:52 -07:00
|
|
|
def info(self, s):
|
2023-03-27 19:59:45 -07:00
|
|
|
self.__logger.info(s)
|
2023-03-27 19:40:52 -07:00
|
|
|
def warn(self, s):
|
2023-03-27 19:59:45 -07:00
|
|
|
self.__logger.warn(s)
|
2023-03-27 19:40:52 -07:00
|
|
|
def error(self, s):
|
2023-03-27 19:59:45 -07:00
|
|
|
self.__logger.error(s)
|