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.

42 lines
1.4 KiB

#!/usr/bin/env python3
"""
测试简化后的日志系统
"""
import sys
import os
# 添加项目根目录到Python路径
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from app.utils.structured_log import get_structured_logger, LogLevel
def test_simple_logging():
"""测试简化后的日志系统"""
print("开始测试简化后的日志系统...")
# 测试不同模块的日志记录器
logger1 = get_structured_logger("test_module_1", LogLevel.DEBUG)
logger2 = get_structured_logger("test_module_2", LogLevel.INFO)
# 测试不同级别的日志
logger1.debug("调试信息 - 模块1", debug_param="value1")
logger1.info("普通信息 - 模块1", info_param="value2")
logger1.warning("警告信息 - 模块1", warning_param="value3")
logger2.info("普通信息 - 模块2", info_param="value4")
logger2.error("错误信息 - 模块2", error_param="value5")
# 测试异常日志
try:
raise ValueError("这是一个测试异常")
except Exception as e:
logger1.exception("捕获到异常", exception_info=str(e))
print("日志测试完成!")
print("请检查以下文件:")
print("- logs/app.log (包含所有日志)")
print("- logs/error.log (只包含错误日志)")
print("- 控制台输出 (实时显示)")
if __name__ == "__main__":
test_simple_logging()