v0.6测试
This commit is contained in:
57
backend/services/log_service.py
Normal file
57
backend/services/log_service.py
Normal file
@@ -0,0 +1,57 @@
|
||||
# ===========================================
|
||||
# 班级操行分管理系统 - 后端服务
|
||||
#
|
||||
# 开发者: Canglan
|
||||
# 联系方式: admin@sea-studio.top
|
||||
# 版权归属: Sea Network Technology Studio
|
||||
# 许可证: MIT License
|
||||
#
|
||||
# 版权所有 © Sea Network Technology Studio
|
||||
# ===========================================
|
||||
|
||||
from models.log import LoginLogModel, OperationLogModel
|
||||
from middleware.permission import PermissionChecker
|
||||
from utils.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
class LogService:
|
||||
"""日志服务"""
|
||||
|
||||
@staticmethod
|
||||
async def write_login_log(username: str, login_result: int, ip: str, user_agent: str = None, fail_reason: str = None):
|
||||
"""
|
||||
写入登录日志(异步,不阻塞主流程)
|
||||
"""
|
||||
try:
|
||||
await LoginLogModel.create(
|
||||
username=username,
|
||||
login_result=login_result,
|
||||
ip_address=ip,
|
||||
user_agent=user_agent,
|
||||
fail_reason=fail_reason
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"写入登录日志失败: {e}")
|
||||
|
||||
@staticmethod
|
||||
async def write_operation_log(operator_id: int, operator_name: str, operator_role: str,
|
||||
operation_type: str, target_type: str = None,
|
||||
target_id: int = None, details: str = None, ip: str = None):
|
||||
"""
|
||||
写入操作日志(异步,不阻塞主流程)
|
||||
"""
|
||||
try:
|
||||
await OperationLogModel.create(
|
||||
operator_id=operator_id,
|
||||
operator_name=operator_name,
|
||||
operator_role=operator_role,
|
||||
operation_type=operation_type,
|
||||
target_type=target_type,
|
||||
target_id=target_id,
|
||||
details=details,
|
||||
ip_address=ip
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"写入操作日志失败: {e}")
|
||||
Reference in New Issue
Block a user