small improvement

This commit is contained in:
əlemi 2022-02-20 14:32:52 +01:00
parent 790f5cbb1f
commit b41f2f6074
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E

View file

@ -8,9 +8,6 @@ def configure_logging(name:str, level=logging.INFO, color:bool = True):
import os import os
from logging.handlers import RotatingFileHandler from logging.handlers import RotatingFileHandler
if not os.path.isdir("debug"):
os.mkdir("debug")
class ColorFormatter(logging.Formatter): class ColorFormatter(logging.Formatter):
def __init__(self, fmt:str): def __init__(self, fmt:str):
self.fmt : str = fmt self.fmt : str = fmt
@ -37,11 +34,7 @@ def configure_logging(name:str, level=logging.INFO, color:bool = True):
ch.setLevel(logging.DEBUG) ch.setLevel(logging.DEBUG)
# create formatter and add it to the handlers # create formatter and add it to the handlers
file_formatter = logging.Formatter("[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s", "%b %d %Y %H:%M:%S") file_formatter = logging.Formatter("[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s", "%b %d %Y %H:%M:%S")
print_formatter : logging.Formatter print_formatter = ColorFormatter("> %(message)s") if color else logging.Formatter("> %(message)s")
if color:
print_formatter = ColorFormatter("> %(message)s")
else:
print_formatter = logging.Formatter("> %(message)s")
fh.setFormatter(file_formatter) fh.setFormatter(file_formatter)
ch.setFormatter(print_formatter) ch.setFormatter(print_formatter)
# add the handlers to the logger # add the handlers to the logger