🤖 自动格式化代码 [skip ci]

This commit is contained in:
github-actions[bot]
2025-06-15 05:46:13 +00:00
parent a9a0ce0447
commit c96963ce6a
2 changed files with 53 additions and 66 deletions

View File

@@ -334,9 +334,9 @@ class HeartFChatting:
"action_result": {
"action_type": "error",
"action_data": {},
"reasoning": f"上下文处理失败: {e}"
"reasoning": f"上下文处理失败: {e}",
},
"observed_messages": ""
"observed_messages": "",
},
"loop_action_info": {"action_taken": False, "reply_text": "", "command": ""},
}
@@ -405,7 +405,7 @@ class HeartFChatting:
logger.error(traceback.format_exc())
# 如果_current_cycle_detail存在但未完成为其设置错误状态
if self._current_cycle_detail and not hasattr(self._current_cycle_detail, 'end_time'):
if self._current_cycle_detail and not hasattr(self._current_cycle_detail, "end_time"):
error_loop_info = {
"loop_observation_info": {},
"loop_processor_info": {},
@@ -413,9 +413,9 @@ class HeartFChatting:
"action_result": {
"action_type": "error",
"action_data": {},
"reasoning": f"循环处理失败: {e}"
"reasoning": f"循环处理失败: {e}",
},
"observed_messages": ""
"observed_messages": "",
},
"loop_action_info": {"action_taken": False, "reply_text": "", "command": ""},
}
@@ -620,12 +620,8 @@ class HeartFChatting:
"loop_observation_info": {},
"loop_processor_info": {},
"loop_plan_info": {
"action_result": {
"action_type": "error",
"action_data": {},
"reasoning": f"处理失败: {e}"
},
"observed_messages": ""
"action_result": {"action_type": "error", "action_data": {}, "reasoning": f"处理失败: {e}"},
"observed_messages": "",
},
"loop_action_info": {"action_taken": False, "reply_text": "", "command": ""},
}

View File

@@ -50,12 +50,12 @@ def get_console_handler():
_console_handler.setLevel(getattr(logging, console_level.upper(), logging.INFO))
return _console_handler
class CompressedRotatingFileHandler(logging.handlers.RotatingFileHandler):
"""支持压缩的轮转文件处理器"""
def __init__(self, filename, maxBytes=0, backupCount=0, encoding=None,
compress=True, compress_level=6):
super().__init__(filename, 'a', maxBytes, backupCount, encoding)
def __init__(self, filename, maxBytes=0, backupCount=0, encoding=None, compress=True, compress_level=6):
super().__init__(filename, "a", maxBytes, backupCount, encoding)
self.compress = compress
self.compress_level = compress_level
@@ -95,11 +95,7 @@ class CompressedRotatingFileHandler(logging.handlers.RotatingFileHandler):
# 在后台线程中压缩文件
if self.compress:
threading.Thread(
target=self._compress_file,
args=(dest_file,),
daemon=True
).start()
threading.Thread(target=self._compress_file, args=(dest_file,), daemon=True).start()
# 重新创建日志文件
if not self.delay:
@@ -114,8 +110,8 @@ class CompressedRotatingFileHandler(logging.handlers.RotatingFileHandler):
compressed_path = Path(f"{filepath}.gz")
with open(source_path, 'rb') as f_in:
with gzip.open(compressed_path, 'wb', compresslevel=self.compress_level) as f_out:
with open(source_path, "rb") as f_in:
with gzip.open(compressed_path, "wb", compresslevel=self.compress_level) as f_out:
shutil.copyfileobj(f_in, f_out)
# 删除原文件
@@ -852,11 +848,11 @@ def initialize_logging():
console_level = LOG_CONFIG.get("console_log_level", LOG_CONFIG.get("log_level", "INFO"))
file_level = LOG_CONFIG.get("file_log_level", LOG_CONFIG.get("log_level", "INFO"))
logger.info(f"日志系统已重新初始化:")
logger.info("日志系统已重新初始化:")
logger.info(f" - 控制台级别: {console_level}")
logger.info(f" - 文件级别: {file_level}")
logger.info(f" - 压缩功能: 启用")
logger.info(f" - 自动清理: 30天前的日志")
logger.info(" - 压缩功能: 启用")
logger.info(" - 自动清理: 30天前的日志")
def force_initialize_logging():
@@ -945,6 +941,7 @@ def cleanup_old_logs():
def start_log_cleanup_task():
"""启动日志清理任务"""
def cleanup_task():
while True:
time.sleep(24 * 60 * 60) # 每24小时执行一次
@@ -959,13 +956,7 @@ def start_log_cleanup_task():
def get_log_stats():
"""获取日志文件统计信息"""
stats = {
"total_files": 0,
"total_size": 0,
"compressed_files": 0,
"uncompressed_files": 0,
"files": []
}
stats = {"total_files": 0, "total_size": 0, "compressed_files": 0, "uncompressed_files": 0, "files": []}
try:
if not LOG_DIR.exists():
@@ -976,7 +967,7 @@ def get_log_stats():
"name": log_file.name,
"size": log_file.stat().st_size,
"modified": datetime.fromtimestamp(log_file.stat().st_mtime).strftime("%Y-%m-%d %H:%M:%S"),
"compressed": log_file.suffix == ".gz"
"compressed": log_file.suffix == ".gz",
}
stats["files"].append(file_info)