You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
926 B
26 lines
926 B
from flask import request
|
|
from loguru import logger
|
|
|
|
|
|
class LogService:
|
|
@staticmethod
|
|
def configure_logging():
|
|
logger.remove() # 移除默认的日志配置
|
|
logger.add(
|
|
"logs/app.log", # 日志文件名
|
|
rotation="1 week", # 每周轮换
|
|
retention="1 month", # 保留一个月
|
|
level="INFO", # 记录 INFO 及以上级别的日志
|
|
format="{time} - {level} - {message}", # 日志格式
|
|
backtrace=True, # 打印完整的异常堆栈
|
|
diagnose=True # 打印详细的异常信息
|
|
)
|
|
|
|
@staticmethod
|
|
def log():
|
|
logger.info(f"Request Path: {request.path}")
|
|
logger.info(f"Request Method: {request.method}")
|
|
logger.info(f"Request Headers: {request.headers}")
|
|
logger.info(f"Request args: {request.args}")
|
|
logger.info(f"Request Body: {request.get_data(as_text=True)}")
|