refactor(event): 将日志级别从info调整为debug,以减少日志输出并提高可读性

This commit is contained in:
Windpicker-owo
2025-10-31 15:15:52 +08:00
parent 94537cf57c
commit c045895754
3 changed files with 40 additions and 56 deletions

View File

@@ -34,51 +34,48 @@ class ProactiveThinkingReplyHandler(BaseEventHandler):
Returns: Returns:
HandlerResult: 处理结果 HandlerResult: 处理结果
""" """
logger.info("[主动思考事件] ProactiveThinkingReplyHandler 开始执行") logger.debug("[主动思考事件] ProactiveThinkingReplyHandler 开始执行")
logger.info(f"[主动思考事件] 接收到的参数: {kwargs}") logger.debug(f"[主动思考事件] 接收到的参数: {kwargs}")
if not kwargs: if not kwargs:
logger.warning("[主动思考事件] kwargs 为空,跳过处理") logger.debug("[主动思考事件] kwargs 为空,跳过处理")
return HandlerResult(success=True, continue_process=True, message=None) return HandlerResult(success=True, continue_process=True, message=None)
stream_id = kwargs.get("stream_id") stream_id = kwargs.get("stream_id")
if not stream_id: if not stream_id:
logger.warning(f"[主动思考事件] Reply事件缺少stream_id参数kwargs={kwargs}") logger.debug(f"[主动思考事件] Reply事件缺少stream_id参数")
return HandlerResult(success=True, continue_process=True, message=None) return HandlerResult(success=True, continue_process=True, message=None)
logger.info(f"[主动思考事件] 收到 AFTER_SEND 事件stream_id={stream_id}") logger.debug(f"[主动思考事件] 收到 AFTER_SEND 事件stream_id={stream_id}")
try: try:
from src.config.config import global_config from src.config.config import global_config
# 检查是否启用reply重置 # 检查是否启用reply重置
logger.info(f"[主动思考事件] reply_reset_enabled={global_config.proactive_thinking.reply_reset_enabled}")
if not global_config.proactive_thinking.reply_reset_enabled: if not global_config.proactive_thinking.reply_reset_enabled:
logger.info(f"[主动思考事件] reply_reset_enabled 为 False跳过重置") logger.debug(f"[主动思考事件] reply_reset_enabled 为 False跳过重置")
return HandlerResult(success=True, continue_process=True, message=None) return HandlerResult(success=True, continue_process=True, message=None)
# 检查是否被暂停 # 检查是否被暂停
was_paused = await proactive_thinking_scheduler.is_paused(stream_id) was_paused = await proactive_thinking_scheduler.is_paused(stream_id)
logger.info(f"[主动思考事件] 聊天流 {stream_id} 暂停状态: {was_paused}") logger.debug(f"[主动思考事件] 聊天流 {stream_id} 暂停状态: {was_paused}")
if was_paused: if was_paused:
logger.info(f"[主动思考事件] 检测到reply事件聊天流 {stream_id} 之前因抛出话题而暂停,现在恢复") logger.debug(f"[主动思考事件] 检测到reply事件聊天流 {stream_id} 之前因抛出话题而暂停,现在恢复")
# 重置定时任务(这会自动清除暂停标记并创建新任务) # 重置定时任务(这会自动清除暂停标记并创建新任务)
logger.info(f"[主动思考事件] 准备调用 schedule_proactive_thinkingstream_id={stream_id}")
success = await proactive_thinking_scheduler.schedule_proactive_thinking(stream_id) success = await proactive_thinking_scheduler.schedule_proactive_thinking(stream_id)
logger.info(f"[主动思考事件] schedule_proactive_thinking 调用完成success={success}")
if success: if success:
if was_paused: if was_paused:
logger.info(f"[主动思考事件] ✅ 聊天流 {stream_id} 主动思考已恢复并重置") logger.info(f"✅ 聊天流 {stream_id} 主动思考已恢复并重置")
else: else:
logger.info(f"[主动思考事件] ✅ 聊天流 {stream_id} 主动思考定时任务已重置") logger.debug(f"✅ 聊天流 {stream_id} 主动思考任务已重置")
else: else:
logger.warning(f"[主动思考事件] ❌ 重置聊天流 {stream_id} 主动思考任务失败") logger.warning(f"❌ 重置聊天流 {stream_id} 主动思考任务失败")
except Exception as e: except Exception as e:
logger.error(f"[主动思考事件] ❌ 处理reply事件时出错: {e}", exc_info=True) logger.error(f"❌ 处理reply事件时出错: {e}", exc_info=True)
# 总是继续处理其他handler # 总是继续处理其他handler
return HandlerResult(success=True, continue_process=True, message=None) return HandlerResult(success=True, continue_process=True, message=None)

View File

@@ -498,72 +498,65 @@ async def execute_proactive_thinking(stream_id: str):
config = global_config.proactive_thinking config = global_config.proactive_thinking
logger.info(f"[主动思考] 开始为聊天流 {stream_id} 执行主动思考") logger.debug(f"🤔 开始主动思考 {stream_id}")
try: try:
# 0. 前置检查 # 0. 前置检查
# 检查是否在安静时段
if proactive_thinking_scheduler._is_in_quiet_hours(): if proactive_thinking_scheduler._is_in_quiet_hours():
logger.debug(f"当前在安静时段,跳过主动思考") logger.debug(f"安静时段,跳过")
return return
# 检查每日限制
if not proactive_thinking_scheduler._check_daily_limit(stream_id): if not proactive_thinking_scheduler._check_daily_limit(stream_id):
logger.info(f"聊天流 {stream_id} 今日主动发言次数已达上限") logger.debug(f"今日发言达上限")
return return
# 1. 搜集信息 # 1. 搜集信息
logger.info(f"[主动思考] 步骤1搜集上下文信息") logger.debug(f"步骤1: 搜集上下文")
context = await _planner.gather_context(stream_id) context = await _planner.gather_context(stream_id)
if not context: if not context:
logger.warning(f"[主动思考] 无法搜集聊天流 {stream_id} 的上下文,跳过本次主动思考") logger.warning(f"无法搜集上下文,跳过")
return return
logger.info(f"[主动思考] 上下文搜集完成")
# 检查兴趣分数阈值 # 检查兴趣分数阈值
interest_score = context.get('interest_score', 0.5) interest_score = context.get('interest_score', 0.5)
if not proactive_thinking_scheduler._check_interest_score_threshold(interest_score): if not proactive_thinking_scheduler._check_interest_score_threshold(interest_score):
logger.info(f"[主动思考] 聊天流 {stream_id} 兴趣分数不在阈值范围内") logger.debug(f"兴趣分数不在阈值范围内")
return return
# 2. 进行决策 # 2. 进行决策
logger.info(f"[主动思考] 步骤2LLM决策") logger.debug(f"步骤2: LLM决策")
decision = await _planner.make_decision(context) decision = await _planner.make_decision(context)
if not decision: if not decision:
logger.warning(f"[主动思考] 决策失败,跳过本次主动思考") logger.warning(f"决策失败,跳过")
return return
logger.info(f"[主动思考] 决策完成")
action = decision.get("action", "do_nothing") action = decision.get("action", "do_nothing")
reasoning = decision.get("reasoning", "") reasoning = decision.get("reasoning", "")
# 记录决策日志 # 记录决策日志
if config.log_decisions: if config.log_decisions:
logger.info(f"[决策详情] stream_id={stream_id}, action={action}, reasoning={reasoning}") logger.debug(f"决策: action={action}, reasoning={reasoning}")
# 3. 根据决策执行相应动作 # 3. 根据决策执行相应动作
if action == "do_nothing": if action == "do_nothing":
logger.info(f"决策:什么都不做。理由:{reasoning}") logger.debug(f"决策:什么都不做。理由:{reasoning}")
# 记录决策
proactive_thinking_scheduler.record_decision(stream_id, action, reasoning, None) proactive_thinking_scheduler.record_decision(stream_id, action, reasoning, None)
return return
elif action == "simple_bubble": elif action == "simple_bubble":
logger.info(f"[主动思考] 决策:简单冒个泡。理由:{reasoning}") logger.info(f"💬 决策:冒个泡。理由:{reasoning}")
# 记录决策
proactive_thinking_scheduler.record_decision(stream_id, action, reasoning, None) proactive_thinking_scheduler.record_decision(stream_id, action, reasoning, None)
# 生成简单的消息 # 生成简单的消息
logger.info(f"[主动思考] 步骤3生成冒泡回复") logger.debug(f"步骤3: 生成冒泡回复")
reply = await _planner.generate_reply(context, "simple_bubble") reply = await _planner.generate_reply(context, "simple_bubble")
if reply: if reply:
logger.info(f"[主动思考] 步骤4发送消息")
await send_api.text_to_stream( await send_api.text_to_stream(
stream_id=stream_id, stream_id=stream_id,
text=reply, text=reply,
) )
logger.info(f"[主动思考] 已发送冒泡消息{stream_id}") logger.info(f" 已发送冒泡消息")
# 增加每日计数 # 增加每日计数
proactive_thinking_scheduler._increment_daily_count(stream_id) proactive_thinking_scheduler._increment_daily_count(stream_id)

View File

@@ -236,28 +236,26 @@ class ProactiveThinkingScheduler:
Returns: Returns:
bool: 是否成功创建/重置任务 bool: 是否成功创建/重置任务
""" """
logger.info(f"[调度器] 开始为聊天流 {stream_id} 创建/重置主动思考任务") logger.debug(f"[调度器] 开始为聊天流 {stream_id} 创建/重置主动思考任务")
try: try:
async with self._lock: async with self._lock:
# 如果该流因抛出话题而暂停,先清除暂停标记 # 如果该流因抛出话题而暂停,先清除暂停标记
if stream_id in self._paused_streams: if stream_id in self._paused_streams:
logger.info(f"[调度器] 清除聊天流 {stream_id} 的暂停标记") logger.debug(f"[调度器] 清除聊天流 {stream_id} 的暂停标记")
self._paused_streams.discard(stream_id) self._paused_streams.discard(stream_id)
# 如果已经有任务,先移除 # 如果已经有任务,先移除
if stream_id in self._stream_schedules: if stream_id in self._stream_schedules:
old_schedule_id = self._stream_schedules[stream_id] old_schedule_id = self._stream_schedules[stream_id]
logger.info(f"[调度器] 移除聊天流 {stream_id} 的旧任务schedule_id={old_schedule_id}") logger.debug(f"[调度器] 移除聊天流 {stream_id} 的旧任务")
await unified_scheduler.remove_schedule(old_schedule_id) await unified_scheduler.remove_schedule(old_schedule_id)
logger.info(f"[调度器] 旧任务已移除")
# 获取 focus_energy 并计算间隔 # 获取 focus_energy 并计算间隔
logger.info(f"[调度器] 开始获取聊天流 {stream_id} 的 focus_energy")
focus_energy = await self._get_stream_focus_energy(stream_id) focus_energy = await self._get_stream_focus_energy(stream_id)
logger.info(f"[调度器] 获取到 focus_energy={focus_energy:.3f}") logger.debug(f"[调度器] focus_energy={focus_energy:.3f}")
interval_seconds = self._calculate_interval(focus_energy) interval_seconds = self._calculate_interval(focus_energy)
logger.info(f"[调度器] 计算得到触发间隔={interval_seconds}秒 ({interval_seconds/60:.1f}分钟)") logger.debug(f"[调度器] 触发间隔={interval_seconds}秒 ({interval_seconds/60:.1f}分钟)")
# 导入回调函数(延迟导入避免循环依赖) # 导入回调函数(延迟导入避免循环依赖)
from src.plugins.built_in.affinity_flow_chatter.proactive_thinking_executor import ( from src.plugins.built_in.affinity_flow_chatter.proactive_thinking_executor import (
@@ -265,7 +263,6 @@ class ProactiveThinkingScheduler:
) )
# 创建新任务 # 创建新任务
logger.info(f"[调度器] 开始创建新的调度任务")
schedule_id = await unified_scheduler.create_schedule( schedule_id = await unified_scheduler.create_schedule(
callback=execute_proactive_thinking, callback=execute_proactive_thinking,
trigger_type=TriggerType.TIME, trigger_type=TriggerType.TIME,
@@ -278,23 +275,20 @@ class ProactiveThinkingScheduler:
) )
self._stream_schedules[stream_id] = schedule_id self._stream_schedules[stream_id] = schedule_id
logger.info(f"[调度器] 新任务已创建schedule_id={schedule_id}")
# 计算下次触发时间 # 计算下次触发时间
next_run_time = datetime.now() + timedelta(seconds=interval_seconds) next_run_time = datetime.now() + timedelta(seconds=interval_seconds)
logger.info( logger.info(
f"[调度器] 聊天流 {stream_id} 创建主动思考任务成功\n" f"✅ 聊天流 {stream_id} 主动思考任务已创建 | "
f" - Focus Energy: {focus_energy:.3f}\n" f"Focus: {focus_energy:.3f} | "
f" - 触发间隔: {interval_seconds}秒 ({interval_seconds/60:.1f}分钟)\n" f"间隔: {interval_seconds/60:.1f}分钟 | "
f" - 下次触发: {next_run_time.strftime('%Y-%m-%d %H:%M:%S')}\n" f"下次: {next_run_time.strftime('%H:%M:%S')}"
f" - Schedule ID: {schedule_id}"
) )
return True return True
except Exception as e: except Exception as e:
logger.error(f"[调度器] ❌ 为聊天流 {stream_id} 创建主动思考任务失败: {e}", exc_info=True) logger.error(f"❌ 创建主动思考任务失败 {stream_id}: {e}", exc_info=True)
logger.error(f"为聊天流 {stream_id} 创建主动思考任务失败: {e}", exc_info=True)
return False return False
async def pause_proactive_thinking(self, stream_id: str, reason: str = "抛出话题") -> bool: async def pause_proactive_thinking(self, stream_id: str, reason: str = "抛出话题") -> bool:
@@ -321,7 +315,7 @@ class ProactiveThinkingScheduler:
if success: if success:
self._paused_streams.add(stream_id) self._paused_streams.add(stream_id)
logger.info(f"暂停聊天流 {stream_id} 的主动思考任务,原因: {reason}") logger.info(f"⏸️ 暂停主动思考 {stream_id},原因: {reason}")
return success return success
@@ -349,12 +343,12 @@ class ProactiveThinkingScheduler:
if success: if success:
self._paused_streams.discard(stream_id) self._paused_streams.discard(stream_id)
logger.info(f"恢复聊天流 {stream_id} 的主动思考任务") logger.info(f"▶️ 恢复主动思考 {stream_id}")
return success return success
except Exception as e: except Exception as e:
logger.error(f"恢复聊天流 {stream_id} 的主动思考任务失败: {e}", exc_info=True) logger.error(f"❌ 恢复主动思考失败 {stream_id}: {e}", exc_info=True)
return False return False
async def cancel_proactive_thinking(self, stream_id: str) -> bool: async def cancel_proactive_thinking(self, stream_id: str) -> bool:
@@ -375,12 +369,12 @@ class ProactiveThinkingScheduler:
self._paused_streams.discard(stream_id) self._paused_streams.discard(stream_id)
success = await unified_scheduler.remove_schedule(schedule_id) success = await unified_scheduler.remove_schedule(schedule_id)
logger.info(f"取消聊天流 {stream_id} 的主动思考任务") logger.debug(f"⏹️ 取消主动思考 {stream_id}")
return success return success
except Exception as e: except Exception as e:
logger.error(f"取消聊天流 {stream_id} 的主动思考任务失败: {e}", exc_info=True) logger.error(f"❌ 取消主动思考失败 {stream_id}: {e}", exc_info=True)
return False return False
async def is_paused(self, stream_id: str) -> bool: async def is_paused(self, stream_id: str) -> bool: