Complete the basic process of code audit

This commit is contained in:
2025-02-09 00:59:35 +08:00
parent eaff2123e7
commit 32e61b8d24
7 changed files with 244 additions and 1 deletions

40
logger/__init__.py Normal file
View File

@@ -0,0 +1,40 @@
from datetime import datetime
LOG_COLORS = {
'DEBUG': '\033[94m', # 蓝色
'INFO': '\033[92m', # 绿色
'WARNING': '\033[93m', # 黄色
'ERROR': '\033[91m', # 红色
'CRITICAL': '\033[95m' # 紫色
}
RESET_COLOR = '\033[0m'
def log_with_color(level, message):
color = LOG_COLORS.get(level, RESET_COLOR)
prefix = f"[{level}]"
date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
formatted_message = f"{color}{date} {prefix} {message}{RESET_COLOR}"
print(formatted_message)
class Logger:
def __init__(self, name):
pass
def debug(self, message):
log_with_color("DEBUG", message)
def info(self, message):
log_with_color("INFO", message)
def warning(self, message):
log_with_color("WARNING", message)
def error(self, message):
log_with_color("ERROR", message)
def critical(self, message):
log_with_color("CRITICAL", message)