diff --git a/app.py b/app.py index 3446c4e..a71bdd4 100755 --- a/app.py +++ b/app.py @@ -3275,15 +3275,30 @@ def run_schedule_now_api(schedule_id): @login_required def get_schedule_logs_api(schedule_id): """获取定时任务执行日志""" - schedule = database.get_schedule_by_id(schedule_id) - if not schedule: - return jsonify({"error": "定时任务不存在"}), 404 - if schedule['user_id'] != current_user.id: - return jsonify({"error": "无权访问"}), 403 + try: + print(f"[API日志] 用户 {current_user.id} 请求查看定时任务#{schedule_id}的执行日志") - limit = request.args.get('limit', 10, type=int) - logs = database.get_schedule_execution_logs(schedule_id, limit) - return jsonify(logs) + schedule = database.get_schedule_by_id(schedule_id) + if not schedule: + print(f"[API日志] 定时任务#{schedule_id}不存在") + return jsonify({"error": "定时任务不存在"}), 404 + + if schedule['user_id'] != current_user.id: + print(f"[API日志] 用户 {current_user.id} 无权访问定时任务#{schedule_id}(属于用户{schedule['user_id']})") + return jsonify({"error": "无权访问"}), 403 + + limit = request.args.get('limit', 10, type=int) + print(f"[API日志] 开始查询定时任务#{schedule_id}的执行日志,限制{limit}条") + + logs = database.get_schedule_execution_logs(schedule_id, limit) + print(f"[API日志] 查询到{len(logs)}条日志") + + return jsonify(logs) + except Exception as e: + print(f"[API日志] 查询定时任务#{schedule_id}日志时出错: {str(e)}") + import traceback + traceback.print_exc() + return jsonify({"error": f"服务器错误: {str(e)}"}), 500 # ==================== 批量操作API ====================