feat(connection): 增加日志记录功能

- 在 connection.py 和 receiveAudioHandle.py 中添加了日志记录功能
- 记录设备 ID、时间戳和模型回复/用户输入的文本
- 优化了日志格式,使其包含更多有用信息
This commit is contained in:
zxb 2025-04-10 13:23:52 +08:00
parent 1bbcb19a52
commit 03cc7318f8
2 changed files with 6 additions and 4 deletions

View file

@ -27,9 +27,9 @@ from config.private_config import PrivateConfig
from core.auth import AuthMiddleware, AuthenticationError from core.auth import AuthMiddleware, AuthenticationError
from core.utils.auth_code_gen import AuthCodeGenerator from core.utils.auth_code_gen import AuthCodeGenerator
from core.mcp.manager import MCPManager from core.mcp.manager import MCPManager
from datetime import datetime
TAG = __name__ TAG = __name__
logger = setup_logging()
auto_import_modules("plugins_func.functions") auto_import_modules("plugins_func.functions")
@ -370,6 +370,8 @@ class ConnectionHandler:
# 处理最后剩余的文本 # 处理最后剩余的文本
full_text = "".join(response_message) full_text = "".join(response_message)
logger.bind(tag=TAG).info(f"deviceId: {self.conn.private_config.device_id},datetime: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")},模型回复: {full_text}")
remaining_text = full_text[processed_chars:] remaining_text = full_text[processed_chars:]
if remaining_text: if remaining_text:
segment_text = get_string_no_punctuation_or_emoji(remaining_text) segment_text = get_string_no_punctuation_or_emoji(remaining_text)

View file

@ -3,7 +3,7 @@ import time
from core.utils.util import remove_punctuation_and_length from core.utils.util import remove_punctuation_and_length
from core.handle.sendAudioHandle import send_stt_message from core.handle.sendAudioHandle import send_stt_message
from core.handle.intentHandler import handle_user_intent from core.handle.intentHandler import handle_user_intent
from datetime import datetime
TAG = __name__ TAG = __name__
logger = setup_logging() logger = setup_logging()
@ -38,7 +38,7 @@ async def handleAudioMessage(conn, audio):
text, file_path = await conn.asr.speech_to_text( text, file_path = await conn.asr.speech_to_text(
conn.asr_audio, conn.session_id conn.asr_audio, conn.session_id
) )
logger.bind(tag=TAG).info(f"识别文本: {text}") logger.bind(tag=TAG).info(f"deviceId: {conn.private_config.device_id},datetime: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")},用户说: {text}")
text_len, _ = remove_punctuation_and_length(text) text_len, _ = remove_punctuation_and_length(text)
if text_len > 0: if text_len > 0:
await startToChat(conn, text) await startToChat(conn, text)