Kamixitong/verify_log.py

41 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import requests
import json
# 直接测试日志API绕过认证检查在实际环境中应该有认证
def test_log_functionality():
"""测试日志功能"""
try:
# 1. 先手动创建一个产品(绕过认证检查)
print("=== 手动创建产品以生成日志 ===")
# 我们直接查看数据库中是否已有产品
print("检查现有产品...")
# 2. 测试获取操作日志(绕过认证检查)
print("\n=== 测试获取操作日志 ===")
# 由于我们无法绕过Flask-Login的认证检查我们直接查看日志文件
print("查看日志文件内容...")
try:
with open('logs/kamaxitong.log', 'r', encoding='utf-8') as f:
lines = f.readlines()
print(f"日志文件共有 {len(lines)}")
# 显示最后几行
for line in lines[-10:]:
print(line.strip())
except FileNotFoundError:
print("日志文件不存在")
except Exception as e:
print(f"读取日志文件失败: {e}")
# 3. 测试审计日志表
print("\n=== 测试审计日志表 ===")
# 我们需要直接连接数据库来查看审计日志
except Exception as e:
print(f"测试过程中出现错误: {e}")
if __name__ == "__main__":
print("验证日志功能...")
test_log_functionality()