2024-05-03 09:08:46 +08:00
|
|
|
# ------ cxykevin log moudle ------
|
|
|
|
# This moudle is not a part of this project.
|
|
|
|
# This file is CopyNone.
|
|
|
|
|
|
|
|
|
|
|
|
import logging
|
|
|
|
from logger import config
|
|
|
|
import sys
|
|
|
|
levels = {
|
|
|
|
"debug": logging.DEBUG,
|
|
|
|
'info': logging.INFO,
|
|
|
|
'warning': logging.WARN,
|
|
|
|
'err': logging.ERROR
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-05-03 18:47:22 +08:00
|
|
|
def log_init() -> None:
|
2024-05-03 09:08:46 +08:00
|
|
|
logging.basicConfig(filename=config.LOGPATH,
|
|
|
|
format='[%(asctime)s][%(levelname)s] %(message)s',
|
2024-05-03 18:47:22 +08:00
|
|
|
level=levels[config.LOGLEVEL], filemode='w')
|
2024-05-03 09:08:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
def info(msg: str) -> None:
|
|
|
|
if (20 >= levels[config.LOGLEVEL]):
|
|
|
|
sys.stdout.write(
|
|
|
|
("[\033[34mINFO\033[0m]" if config.OUTPUT_COLORFUL else "[INFO]") + msg + "\n")
|
|
|
|
logging.info(msg)
|
|
|
|
|
|
|
|
|
|
|
|
def warn(msg: str) -> None:
|
|
|
|
if (30 >= levels[config.LOGLEVEL]):
|
|
|
|
sys.stdout.write(
|
|
|
|
("[\033[33mWARNING\033[0m]" if config.OUTPUT_COLORFUL else "[WARNING]") + msg + "\n")
|
|
|
|
logging.warn(msg)
|
|
|
|
|
|
|
|
|
|
|
|
def err(msg: str) -> None:
|
|
|
|
if (40 >= levels[config.LOGLEVEL]):
|
|
|
|
sys.stdout.write(
|
|
|
|
("[\033[31mERROR\033[0m]" if config.OUTPUT_COLORFUL else "[ERROR]") + msg + "\n")
|
|
|
|
logging.error(msg)
|
|
|
|
|
|
|
|
|
|
|
|
def break_err(msg: str) -> None:
|
|
|
|
if (40 >= levels[config.LOGLEVEL]):
|
|
|
|
sys.stdout.write(
|
|
|
|
("[\033[31mERROR\033[0m]" if config.OUTPUT_COLORFUL else "[ERROR]") + msg + "\n")
|
|
|
|
logging.error(msg)
|
|
|
|
|
|
|
|
|
|
|
|
def print(*args, end="\n") -> None:
|
|
|
|
msg = ' '.join(map(str, args))
|
|
|
|
if (10 >= levels[config.LOGLEVEL]):
|
|
|
|
sys.stdout.write(msg + end)
|
|
|
|
logging.debug(msg)
|
2024-05-03 18:47:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
def trace_sys(msg: str) -> None:
|
|
|
|
logging.info(msg)
|