feat: 更新配置文件,启用开关并优化日志格式化,增强耗时字段处理
This commit is contained in:
1 parent
1105ed618f
commit
1223a1ea5a
4 files changed
+133
-66
No files matched your search
+5
-5
@@ -1,16 +1,16 @@
|
||||
{
|
||||
"needswitch": false,
|
||||
"needswitch": true,
|
||||
"infinite_loop_enabled": true,
|
||||
"wait_minutes": 5,
|
||||
"min_prize_value_yuan": 200.0,
|
||||
"min_participants": 0,
|
||||
"max_participants": 0,
|
||||
"skip_if_countdown_gt_seconds": 1800,
|
||||
"skip_if_countdown_gt_seconds": 180,
|
||||
"reset_after_swipes_enabled": true,
|
||||
"reset_after_swipes": 10,
|
||||
"auto_join_fansclub": true,
|
||||
"fansclub_fail_action": "switch",
|
||||
"high_value_fudai_enabled": false,
|
||||
"high_value_fudai_enabled": true,
|
||||
"high_value_fudai_threshold_yuan": 500.0,
|
||||
"high_value_fudai_join_ahead_seconds": 120,
|
||||
"high_value_fudai_max_swipe_back": 50,
|
||||
@@ -102,9 +102,9 @@
|
||||
"beautify_output": true,
|
||||
"show_timestamps": true,
|
||||
"show_execution_times": true,
|
||||
"debug_detail_level": "detailed",
|
||||
"debug_detail_level": "normal",
|
||||
"error_detail_level": "full",
|
||||
"action_log_format": "detailed",
|
||||
"action_log_format": "concise",
|
||||
"color_output": true,
|
||||
"max_log_lines_display": 1000,
|
||||
"auto_scroll_logs": true,
|
||||
|
||||
@@ -1,8 +1,37 @@
|
||||
{
|
||||
"updated_ts": 1767414612.3390598,
|
||||
"reason": "startup_clear",
|
||||
"room_pos": 0,
|
||||
"current_room_title": "",
|
||||
"current_room_title_raw": "",
|
||||
"reservations": []
|
||||
}
|
||||
"updated_ts": 1767415357.50075,
|
||||
"reason": "record_reservation",
|
||||
"room_pos": 1,
|
||||
"current_room_title": "扬叔来了",
|
||||
"current_room_title_raw": "扬叔来了",
|
||||
"reservations": [
|
||||
{
|
||||
"prize_value_yuan": 5999.0,
|
||||
"content": "",
|
||||
"future_ts": 1767415961.174306,
|
||||
"future_str": "2026-01-03 12:52:41",
|
||||
"pos_seen": 0,
|
||||
"room_title": "一枝梅3号",
|
||||
"room_title_raw": "一枝梅3号",
|
||||
"created_ts": 1767415328.6684387,
|
||||
"task_count": 2,
|
||||
"time_text": "10:38",
|
||||
"participants": 0,
|
||||
"copies": 0
|
||||
},
|
||||
{
|
||||
"prize_value_yuan": 3399.0,
|
||||
"content": "",
|
||||
"future_ts": 1767416222.371734,
|
||||
"future_str": "2026-01-03 12:57:02",
|
||||
"pos_seen": 1,
|
||||
"room_title": "扬叔来了",
|
||||
"room_title_raw": "扬叔来了",
|
||||
"created_ts": 1767415357.4982371,
|
||||
"task_count": 2,
|
||||
"time_text": "14:30",
|
||||
"participants": 0,
|
||||
"copies": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -371,40 +371,51 @@ class LoggingWrapper:
|
||||
else:
|
||||
action_desc = "操作"
|
||||
|
||||
# 归一化字段名,支持以 '字段_' 前缀的字段名向后兼容
|
||||
fields_clean: Dict[str, Any] = {}
|
||||
for k, v in fields.items():
|
||||
kk = str(k)
|
||||
if kk.startswith("字段_"):
|
||||
kk = kk[len("字段_"):]
|
||||
fields_clean[kk] = v
|
||||
|
||||
# 提取耗时(从字段中查找,优先使用毫秒字段)
|
||||
elapsed_str = ""
|
||||
if "elapsed_ms" in fields:
|
||||
elapsed_seconds = float(fields.get("elapsed_ms", 0)) / 1000.0
|
||||
if "elapsed_ms" in fields_clean:
|
||||
elapsed_seconds = float(fields_clean.get("elapsed_ms", 0)) / 1000.0
|
||||
elapsed_str = f"耗时:{elapsed_seconds:.2f}s"
|
||||
elif "total_elapsed_ms" in fields:
|
||||
elapsed_seconds = float(fields.get("total_elapsed_ms", 0)) / 1000.0
|
||||
elif "total_ms" in fields_clean:
|
||||
elapsed_seconds = float(fields_clean.get("total_ms", 0)) / 1000.0
|
||||
elapsed_str = f"耗时:{elapsed_seconds:.2f}s"
|
||||
elif "总耗时毫秒" in fields:
|
||||
elapsed_seconds = float(fields.get("总耗时毫秒", 0)) / 1000.0
|
||||
elif "total_elapsed_ms" in fields_clean:
|
||||
elapsed_seconds = float(fields_clean.get("total_elapsed_ms", 0)) / 1000.0
|
||||
elapsed_str = f"耗时:{elapsed_seconds:.2f}s"
|
||||
elif "seconds" in fields:
|
||||
elapsed_seconds = float(fields.get("seconds", 0))
|
||||
elif "总耗时毫秒" in fields_clean:
|
||||
elapsed_seconds = float(fields_clean.get("总耗时毫秒", 0)) / 1000.0
|
||||
elapsed_str = f"耗时:{elapsed_seconds:.2f}s"
|
||||
elif "elapsed_seconds" in fields:
|
||||
elapsed_seconds = float(fields.get("elapsed_seconds", 0))
|
||||
elif "seconds" in fields_clean:
|
||||
elapsed_seconds = float(fields_clean.get("seconds", 0))
|
||||
elapsed_str = f"耗时:{elapsed_seconds:.2f}s"
|
||||
elif "elapsed_seconds" in fields_clean:
|
||||
elapsed_seconds = float(fields_clean.get("elapsed_seconds", 0))
|
||||
elapsed_str = f"耗时:{elapsed_seconds:.2f}s"
|
||||
|
||||
# 提取分数(如果有)
|
||||
score_str = ""
|
||||
if "score" in fields and fields.get("score") is not None:
|
||||
if "score" in fields_clean and fields_clean.get("score") is not None:
|
||||
try:
|
||||
score_val = float(fields.get("score", 0))
|
||||
score_val = float(fields_clean.get("score", 0))
|
||||
score_str = f"分数:{score_val:.3f}"
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
elif "max_val" in fields and fields.get("max_val") is not None:
|
||||
elif "max_val" in fields_clean and fields_clean.get("max_val") is not None:
|
||||
try:
|
||||
score_val = float(fields.get("max_val", 0))
|
||||
score_val = float(fields_clean.get("max_val", 0))
|
||||
score_str = f"分数:{score_val:.3f}"
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
elif "分数" in fields:
|
||||
score_field = fields.get("分数")
|
||||
elif "分数" in fields_clean:
|
||||
score_field = fields_clean.get("分数")
|
||||
# 允许显示0.0分数,只要不是None
|
||||
if score_field is not None:
|
||||
try:
|
||||
@@ -450,50 +461,42 @@ class LoggingWrapper:
|
||||
if log_dir:
|
||||
os.makedirs(log_dir, exist_ok=True)
|
||||
|
||||
# 检测标签变化,用====分隔不同步骤
|
||||
# 使用实例变量记录上一个标签
|
||||
# 检测标签变化,并写入行为日志(始终写入,首次也会写)
|
||||
if not hasattr(analyser, "_last_action_tag"):
|
||||
analyser._last_action_tag = None
|
||||
|
||||
# 如果标签变化,添加分隔符
|
||||
current_tag = tag or "[日志]"
|
||||
if (
|
||||
analyser._last_action_tag is not None
|
||||
and analyser._last_action_tag != current_tag
|
||||
):
|
||||
# 如果标签变化,添加分隔符(增加到80个等号)
|
||||
try:
|
||||
import logging
|
||||
try:
|
||||
import logging
|
||||
|
||||
action_logger = logging.getLogger("action_logger")
|
||||
# 使用 action_logger 写入,避免直接打开文件导致与 RotatingFileHandler 冲突
|
||||
if (
|
||||
analyser._last_action_tag is not None
|
||||
and analyser._last_action_tag != current_tag
|
||||
):
|
||||
action_logger.info("=" * 80)
|
||||
action_logger = logging.getLogger("action_logger")
|
||||
# 如果标签变化,先写分隔符
|
||||
if (
|
||||
analyser._last_action_tag is not None
|
||||
and analyser._last_action_tag != current_tag
|
||||
):
|
||||
action_logger.info("=" * 80)
|
||||
|
||||
analyser._last_action_tag = current_tag
|
||||
|
||||
# 写入精简行为日志行到 action_logger,让文件处理由 RotatingFileHandler 管理
|
||||
action_logger.info(action_log_line)
|
||||
except Exception:
|
||||
# 回退到直接写文件(兼容场景)
|
||||
if log_dir:
|
||||
with open(
|
||||
actions_log_path,
|
||||
"a",
|
||||
encoding="utf-8-sig",
|
||||
errors="replace",
|
||||
) as f:
|
||||
if (
|
||||
analyser._last_action_tag is not None
|
||||
and analyser._last_action_tag != current_tag
|
||||
):
|
||||
f.write("=" * 80 + "\n")
|
||||
analyser._last_action_tag = current_tag
|
||||
f.write(action_log_line + "\n")
|
||||
f.flush()
|
||||
# 始终写入精简行为日志行到 action_logger(由 RotatingFileHandler 管理)
|
||||
action_logger.info(action_log_line)
|
||||
analyser._last_action_tag = current_tag
|
||||
except Exception:
|
||||
# 回退到直接写文件(兼容场景)
|
||||
if log_dir:
|
||||
with open(
|
||||
actions_log_path,
|
||||
"a",
|
||||
encoding="utf-8-sig",
|
||||
errors="replace",
|
||||
) as f:
|
||||
if (
|
||||
analyser._last_action_tag is not None
|
||||
and analyser._last_action_tag != current_tag
|
||||
):
|
||||
f.write("=" * 80 + "\n")
|
||||
analyser._last_action_tag = current_tag
|
||||
f.write(action_log_line + "\n")
|
||||
f.flush()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@@ -62,6 +62,41 @@ def format_action_log(action: str, details: Optional[str] = None, **fields: Any)
|
||||
if elapsed is not None:
|
||||
kv_parts.append(f"耗时={round(elapsed,2)}s")
|
||||
|
||||
# 专门处理以 `_ms` 命名的耗时字段,使用友好中文标签并统一以 ms 单位显示
|
||||
ms_kv_parts: list[str] = []
|
||||
ms_keys = [k for k in list(fields.keys()) if "_ms" in k]
|
||||
if ms_keys:
|
||||
# 常见 ms 字段到中文的映射
|
||||
ms_label_map = {
|
||||
"total_ms": "总耗时",
|
||||
"ocr_ms": "OCR耗时",
|
||||
"image_load_ms": "图像加载耗时",
|
||||
"countdown_parse_ms": "倒计时解析耗时",
|
||||
"render_ms": "渲染耗时",
|
||||
"detection_ms": "检测耗时",
|
||||
"ocr_value_ms": "OCR价值耗时",
|
||||
}
|
||||
for k in ms_keys:
|
||||
v = fields.pop(k, None)
|
||||
try:
|
||||
num = float(v)
|
||||
ms_str = f"{num:.2f}ms"
|
||||
except Exception:
|
||||
ms_str = f"{v}"
|
||||
|
||||
label = ms_label_map.get(k, None)
|
||||
if label:
|
||||
ms_kv_parts.append(f"{label}={ms_str}")
|
||||
else:
|
||||
# 将 key 转为更可读形式,例如 ocr_ms -> ocr ms
|
||||
pretty_key = k.replace("_", " ")
|
||||
ms_kv_parts.append(f"{pretty_key}={ms_str}")
|
||||
|
||||
# 如果存在 ms 字段,向人类可读部分追加显眼的标签
|
||||
human_parts.append("关键耗时(ms)")
|
||||
# 把 ms 字段放在其它 kv 之前,增强可读性
|
||||
kv_parts = ms_kv_parts + kv_parts
|
||||
|
||||
# 如果有 slow 标记,转换为中文提示
|
||||
if "slow" in fields:
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user