zhitou_trade/bbb.py
2025-05-22 16:47:45 +08:00

40 lines
1.1 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.

# utils.py - 工具模块,使用日志功能
import logging
import logging
# 获取子模块logger
logger = logging.getLogger(__name__)
# 添加专属文件处理器(只添加一次)
if not logger.handlers:
# 专属文件处理器
module_file_handler = logging.FileHandler('utils.log')
module_file_handler.setLevel(logging.DEBUG)
# 设置专属格式(可选)
module_formatter = logging.Formatter(
'[%(asctime)s] %(levelname)s @ %(funcName)s: %(message)s'
)
module_file_handler.setFormatter(module_formatter)
logger.addHandler(module_file_handler)
logger.propagate = True # 仍然传播到root logger主日志文件
def process_data(data):
"""数据处理函数"""
logger.debug(f"开始处理数据: {data}")
try:
# 模拟数据处理
result = [x * 2 for x in data]
# 模拟一个调试信息
logger.info(f"中间结果: {result}")
return result
except Exception as e:
logger.error(f"数据处理失败: {str(e)}", exc_info=True)
raise