统一日志详细度入口
This commit is contained in:
1 parent
198a30dce1
commit
daf0c49288
11 files changed
+411
-56
No files matched your search
@@ -21,28 +21,40 @@ from ._common import (
|
||||
_performance_tracker,
|
||||
)
|
||||
|
||||
_SIMPLE_NOISE_LOG_TYPES = {"DEBUG", "PERF", "SCREENSHOT", "FLOW"}
|
||||
_SIMPLE_NOISE_LOG_TYPES = {"DEBUG", "PERF", "SCREENSHOT", "FLOW", "OCR_SUMMARY"}
|
||||
_SIMPLE_NOISE_TAGS = {
|
||||
"OCR",
|
||||
"OCR摘要",
|
||||
"性能",
|
||||
"验证",
|
||||
"流程标志",
|
||||
"调试图像",
|
||||
"步骤耗时",
|
||||
"福袋倒计时",
|
||||
"[性能]",
|
||||
"[验证]",
|
||||
"[流程标志]",
|
||||
"[调试图像]",
|
||||
"[步骤耗时]",
|
||||
"[福袋倒计时]",
|
||||
}
|
||||
_SIMPLE_NOISE_PATTERNS = (
|
||||
"[FLOW_FLAG]",
|
||||
"OCR摘要",
|
||||
"OCR调试(",
|
||||
"OCR识别任务列表区域",
|
||||
"OCR结果完全为空",
|
||||
"分割识别失败",
|
||||
"result[0] keys=",
|
||||
"dt_polys",
|
||||
"rec_texts",
|
||||
"调试图像",
|
||||
"综合标注图已保存",
|
||||
"像素阶段总览保存",
|
||||
"关键耗时",
|
||||
"read_fudai_detail_once:",
|
||||
)
|
||||
_SIMPLE_MAX_LINE_LEN = 220
|
||||
_SIMPLE_MAX_LINE_LEN = 150
|
||||
|
||||
|
||||
def _clean_simple_tag(tag: str) -> str:
|
||||
@@ -60,19 +72,24 @@ def _should_skip_simple_stdout(
|
||||
if fields.get("exc_info") is not None:
|
||||
return False
|
||||
|
||||
if str(log_level or "").upper() in {"WARNING", "ERROR", "CRITICAL"}:
|
||||
level = str(log_level or "").upper()
|
||||
if level in {"ERROR", "CRITICAL"}:
|
||||
return False
|
||||
|
||||
tag_clean = _clean_simple_tag(tag)
|
||||
if tag_clean in _SIMPLE_NOISE_TAGS:
|
||||
return True
|
||||
|
||||
log_type = str(fields.get("_log_type", "") or "").upper()
|
||||
if log_type in _SIMPLE_NOISE_LOG_TYPES:
|
||||
return True
|
||||
|
||||
text = f"{tag} {msg} {log_line}"
|
||||
if any(pattern in text for pattern in _SIMPLE_NOISE_PATTERNS):
|
||||
|
||||
is_noise = (
|
||||
tag_clean in _SIMPLE_NOISE_TAGS
|
||||
or log_type in _SIMPLE_NOISE_LOG_TYPES
|
||||
or any(pattern in text for pattern in _SIMPLE_NOISE_PATTERNS)
|
||||
)
|
||||
if level == "WARNING":
|
||||
return is_noise
|
||||
|
||||
if is_noise:
|
||||
return True
|
||||
|
||||
return False
|
||||
@@ -84,6 +101,83 @@ def _compact_simple_line(log_line: str) -> str:
|
||||
return log_line[: _SIMPLE_MAX_LINE_LEN - 3].rstrip() + "..."
|
||||
|
||||
|
||||
def _format_simple_stdout_line(
|
||||
tag: str,
|
||||
msg: str,
|
||||
log_level: str,
|
||||
timestamp: str,
|
||||
fields: Dict[str, Any],
|
||||
fallback_line: str,
|
||||
) -> str:
|
||||
"""日常模式只保留短时间、标签、业务消息和少量结果字段。"""
|
||||
parts: list[str] = []
|
||||
if timestamp:
|
||||
parts.append(f"[{timestamp[-12:-4]}]")
|
||||
|
||||
level = str(log_level or "INFO").upper()
|
||||
if level not in {"INFO", ""}:
|
||||
parts.append(f"[{level}]")
|
||||
|
||||
tag_clean = _clean_simple_tag(tag)
|
||||
if tag_clean:
|
||||
parts.append(f"[{tag_clean}]")
|
||||
|
||||
msg_clean = str(msg or "").replace("\r", " ").replace("\n", " ").strip()
|
||||
if msg_clean:
|
||||
parts.append(msg_clean[:80])
|
||||
|
||||
key_map = {
|
||||
"elapsed_seconds": "耗时",
|
||||
"elapsed_ms": "耗时",
|
||||
"value_yuan": "价值",
|
||||
"room_pos": "位置",
|
||||
"future_ts": "开奖",
|
||||
"actual_remaining_seconds": "剩余",
|
||||
"实际_剩余秒数": "剩余",
|
||||
"实际_价值": "价值",
|
||||
"实际_内容": "内容",
|
||||
"button_text": "按钮",
|
||||
"按钮文本": "按钮",
|
||||
"error": "错误",
|
||||
}
|
||||
field_parts: list[str] = []
|
||||
for key in (
|
||||
"value_yuan",
|
||||
"实际_价值",
|
||||
"actual_remaining_seconds",
|
||||
"实际_剩余秒数",
|
||||
"button_text",
|
||||
"按钮文本",
|
||||
"room_pos",
|
||||
"elapsed_seconds",
|
||||
"elapsed_ms",
|
||||
"error",
|
||||
):
|
||||
if key not in fields or fields.get(key) is None:
|
||||
continue
|
||||
value = fields.get(key)
|
||||
if isinstance(value, float):
|
||||
if "seconds" in key or "剩余" in key:
|
||||
value_str = f"{value:.0f}s"
|
||||
elif "ms" in key:
|
||||
value_str = f"{value:.0f}ms"
|
||||
elif "价值" in key or "yuan" in key:
|
||||
value_str = f"{value:.0f}元"
|
||||
else:
|
||||
value_str = f"{value:.1f}"
|
||||
else:
|
||||
value_str = str(value).strip()
|
||||
if not value_str:
|
||||
continue
|
||||
field_parts.append(f"{key_map.get(key, key)}={value_str[:36]}")
|
||||
|
||||
if field_parts:
|
||||
parts.append(" ".join(field_parts[:4]))
|
||||
|
||||
line = " ".join(parts).strip() or fallback_line
|
||||
return _compact_simple_line(line)
|
||||
|
||||
|
||||
def _enhanced_log_kv_simple(
|
||||
analyser: Any,
|
||||
tag: str,
|
||||
@@ -97,10 +191,17 @@ def _enhanced_log_kv_simple(
|
||||
color: Optional[str] = None,
|
||||
) -> None:
|
||||
"""简洁模式的日志记录"""
|
||||
# 构建简洁的日志行
|
||||
log_line = _compact_simple_line(" ".join(log_parts))
|
||||
if _should_skip_simple_stdout(tag, msg, log_level, fields, log_line):
|
||||
fallback_line = _compact_simple_line(" ".join(log_parts))
|
||||
if _should_skip_simple_stdout(tag, msg, log_level, fields, fallback_line):
|
||||
return
|
||||
log_line = _format_simple_stdout_line(
|
||||
tag,
|
||||
msg,
|
||||
log_level,
|
||||
timestamp,
|
||||
fields,
|
||||
fallback_line,
|
||||
)
|
||||
|
||||
# 输出分隔符(如果需要)- 使用更简洁的分隔符
|
||||
if need_separator:
|
||||
|
||||
@@ -64,6 +64,8 @@ def apply_logging_from_cfg(vars_: Dict[str, tk.Variable], cfg: dict) -> None:
|
||||
logging_config = cfg.get("logging", {})
|
||||
if not isinstance(logging_config, dict):
|
||||
return
|
||||
log_format_mode = _normalize_log_format_mode(logging_config.get("log_format_mode", "simple"))
|
||||
derived_logging = _derive_logging_detail_fields(log_format_mode)
|
||||
vars_["logging_beautify_var"].set(bool(logging_config.get("beautify_output", True)))
|
||||
vars_["logging_color_var"].set(bool(logging_config.get("color_output", True)))
|
||||
vars_["logging_show_timestamps_var"].set(bool(logging_config.get("show_timestamps", True)))
|
||||
@@ -75,10 +77,10 @@ def apply_logging_from_cfg(vars_: Dict[str, tk.Variable], cfg: dict) -> None:
|
||||
vars_["logging_compress_logs_var"].set(bool(logging_config.get("compress_logs", True)))
|
||||
vars_["logging_max_total_size_gb_var"].set(float(logging_config.get("max_total_size_gb", 10.0) or 10.0))
|
||||
vars_["logging_compress_after_days_var"].set(int(logging_config.get("compress_after_days", 7) or 7))
|
||||
vars_["logging_debug_level_var"].set("normal")
|
||||
vars_["logging_error_level_var"].set("full")
|
||||
vars_["logging_action_format_var"].set("concise")
|
||||
vars_["logging_format_mode_var"].set("simple")
|
||||
vars_["logging_debug_level_var"].set(derived_logging["debug_detail_level"])
|
||||
vars_["logging_error_level_var"].set(derived_logging["error_detail_level"])
|
||||
vars_["logging_action_format_var"].set(derived_logging["action_log_format"])
|
||||
vars_["logging_format_mode_var"].set(log_format_mode)
|
||||
perf_cfg = logging_config.get("performance_tracking", {})
|
||||
if isinstance(perf_cfg, dict):
|
||||
vars_["logging_performance_enabled_var"].set(bool(perf_cfg.get("enabled", True)))
|
||||
@@ -101,6 +103,8 @@ def write_debug_captures_to_cfg(cfg2: dict, vars_: Dict[str, tk.Variable]) -> No
|
||||
def write_logging_to_cfg(cfg2: dict, vars_: Dict[str, tk.Variable]) -> None:
|
||||
if "logging" not in cfg2 or not isinstance(cfg2["logging"], dict):
|
||||
cfg2["logging"] = {}
|
||||
log_format_mode = _normalize_log_format_mode(vars_["logging_format_mode_var"].get())
|
||||
derived_logging = _derive_logging_detail_fields(log_format_mode)
|
||||
cfg2["logging"]["beautify_output"] = bool(vars_["logging_beautify_var"].get())
|
||||
cfg2["logging"]["color_output"] = bool(vars_["logging_color_var"].get())
|
||||
cfg2["logging"]["show_timestamps"] = bool(vars_["logging_show_timestamps_var"].get())
|
||||
@@ -110,10 +114,10 @@ def write_logging_to_cfg(cfg2: dict, vars_: Dict[str, tk.Variable]) -> None:
|
||||
cfg2["logging"]["compress_logs"] = bool(vars_["logging_compress_logs_var"].get())
|
||||
cfg2["logging"]["max_total_size_gb"] = float(vars_["logging_max_total_size_gb_var"].get() or 10.0)
|
||||
cfg2["logging"]["compress_after_days"] = int(vars_["logging_compress_after_days_var"].get() or 7)
|
||||
cfg2["logging"]["debug_detail_level"] = "normal"
|
||||
cfg2["logging"]["error_detail_level"] = "full"
|
||||
cfg2["logging"]["action_log_format"] = "concise"
|
||||
cfg2["logging"]["log_format_mode"] = "simple"
|
||||
cfg2["logging"]["debug_detail_level"] = derived_logging["debug_detail_level"]
|
||||
cfg2["logging"]["error_detail_level"] = derived_logging["error_detail_level"]
|
||||
cfg2["logging"]["action_log_format"] = derived_logging["action_log_format"]
|
||||
cfg2["logging"]["log_format_mode"] = log_format_mode
|
||||
cfg2["logging"]["stage_diag_verbose"] = bool(vars_["stage_diag_verbose_var"].get())
|
||||
cfg2["logging"]["monitor_warning_mb"] = float(vars_["logging_monitor_warning_mb_var"].get() or 500.0)
|
||||
cfg2["logging"]["monitor_critical_mb"] = float(vars_["logging_monitor_critical_mb_var"].get() or 2000.0)
|
||||
@@ -124,3 +128,22 @@ def write_logging_to_cfg(cfg2: dict, vars_: Dict[str, tk.Variable]) -> None:
|
||||
cfg2["logging"]["performance_tracking"]["track_function_calls"] = bool(vars_["logging_track_functions_var"].get())
|
||||
cfg2["log_unified_enabled"] = bool(vars_["log_unified_enabled_var"].get())
|
||||
cfg2["log_unified_path"] = str(vars_["log_unified_path_var"].get() or "logs/unified.log")
|
||||
|
||||
|
||||
def _normalize_log_format_mode(value: object) -> str:
|
||||
mode = str(value or "simple").strip().lower()
|
||||
return mode if mode in {"simple", "detailed"} else "simple"
|
||||
|
||||
|
||||
def _derive_logging_detail_fields(log_format_mode: str) -> dict:
|
||||
if _normalize_log_format_mode(log_format_mode) == "detailed":
|
||||
return {
|
||||
"debug_detail_level": "detailed",
|
||||
"error_detail_level": "full",
|
||||
"action_log_format": "detailed",
|
||||
}
|
||||
return {
|
||||
"debug_detail_level": "normal",
|
||||
"error_detail_level": "full",
|
||||
"action_log_format": "concise",
|
||||
}
|
||||
@@ -15,6 +15,11 @@ from __future__ import annotations
|
||||
import tkinter as tk
|
||||
from typing import Callable, Dict
|
||||
|
||||
from gui.components.config_io_helpers import (
|
||||
_derive_logging_detail_fields,
|
||||
_normalize_log_format_mode,
|
||||
)
|
||||
|
||||
|
||||
def save_logging_config(
|
||||
*,
|
||||
@@ -32,14 +37,17 @@ def save_logging_config(
|
||||
if "logging" not in cfg:
|
||||
cfg["logging"] = {}
|
||||
|
||||
cfg["logging"]["log_format_mode"] = "simple"
|
||||
log_format_mode = _normalize_log_format_mode(vars_["logging_format_mode_var"].get())
|
||||
derived_logging = _derive_logging_detail_fields(log_format_mode)
|
||||
|
||||
cfg["logging"]["log_format_mode"] = log_format_mode
|
||||
cfg["logging"]["beautify_output"] = bool(vars_["logging_beautify_var"].get())
|
||||
cfg["logging"]["color_output"] = bool(vars_["logging_color_var"].get())
|
||||
cfg["logging"]["show_timestamps"] = bool(vars_["logging_show_timestamps_var"].get())
|
||||
cfg["logging"]["use_dated_logs"] = bool(vars_["logging_use_dated_logs_var"].get())
|
||||
cfg["logging"]["debug_detail_level"] = "normal"
|
||||
cfg["logging"]["debug_detail_level"] = derived_logging["debug_detail_level"]
|
||||
cfg["logging"]["error_detail_level"] = "full"
|
||||
cfg["logging"]["action_log_format"] = "concise"
|
||||
cfg["logging"]["action_log_format"] = derived_logging["action_log_format"]
|
||||
cfg["logging"]["enable_monitor"] = bool(vars_["logging_enable_monitor_var"].get())
|
||||
cfg["logging"]["keep_days"] = int(vars_["logging_keep_days_var"].get())
|
||||
cfg["logging"]["compress_logs"] = bool(vars_["logging_compress_logs_var"].get())
|
||||
|
||||
@@ -32,12 +32,19 @@ def setup_logging_tab(
|
||||
log_format_box = ttk.LabelFrame(logging_container, text="日志格式")
|
||||
log_format_box.pack(fill=X, pady=(0, 10))
|
||||
|
||||
# Simple 是唯一日常显示模式;详细调试信息留在内部 debug 日志。
|
||||
log_format_r1 = ttk.Frame(log_format_box)
|
||||
log_format_r1.pack(fill=X, padx=10, pady=(10, 6))
|
||||
ttk.Label(log_format_r1, text="日志格式模式:").pack(side=LEFT)
|
||||
ttk.Combobox(
|
||||
log_format_r1,
|
||||
textvariable=vars_["logging_format_mode_var"],
|
||||
values=["simple", "detailed"],
|
||||
state="readonly",
|
||||
width=12,
|
||||
).pack(side=LEFT, padx=(6, 16))
|
||||
ttk.Label(
|
||||
log_format_r1,
|
||||
text="日志显示模式:simple(统一简洁模式,调试细节自动收进 debug/detail)",
|
||||
text="simple=日常极简,detailed=调试详细;其它日志详细度自动跟随",
|
||||
).pack(side=LEFT)
|
||||
|
||||
# 日志美化选项
|
||||
|
||||
@@ -446,12 +446,12 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
"reset_after_swipes_action",
|
||||
"reenter_live_entry_mode",
|
||||
"fudai_detail_ui_mode",
|
||||
"logging.log_format_mode",
|
||||
}
|
||||
fixed_simple_logging = {
|
||||
"logging.debug_detail_level": "normal",
|
||||
"logging.error_detail_level": "full",
|
||||
"logging.action_log_format": "concise",
|
||||
"logging.log_format_mode": "simple",
|
||||
derived_logging_keys = {
|
||||
"logging.debug_detail_level",
|
||||
"logging.error_detail_level",
|
||||
"logging.action_log_format",
|
||||
}
|
||||
|
||||
def set_nested_value(obj, key, value):
|
||||
@@ -466,10 +466,35 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
else:
|
||||
obj[key] = value
|
||||
|
||||
def get_nested_value(obj, key, default=None):
|
||||
current = obj
|
||||
for part in key.split("."):
|
||||
if not isinstance(current, dict) or part not in current:
|
||||
return default
|
||||
current = current[part]
|
||||
return current
|
||||
|
||||
def normalize_log_format_mode(value):
|
||||
mode = str(value or "simple").strip().lower()
|
||||
return mode if mode in ("simple", "detailed") else "simple"
|
||||
|
||||
def apply_derived_logging_fields():
|
||||
mode = normalize_log_format_mode(
|
||||
get_nested_value(cfg, "logging.log_format_mode", "simple")
|
||||
)
|
||||
set_nested_value(cfg, "logging.log_format_mode", mode)
|
||||
if mode == "detailed":
|
||||
set_nested_value(cfg, "logging.debug_detail_level", "detailed")
|
||||
set_nested_value(cfg, "logging.action_log_format", "detailed")
|
||||
else:
|
||||
set_nested_value(cfg, "logging.debug_detail_level", "normal")
|
||||
set_nested_value(cfg, "logging.action_log_format", "concise")
|
||||
set_nested_value(cfg, "logging.error_detail_level", "full")
|
||||
|
||||
for k, v in (update or {}).items():
|
||||
if k in deny_keys:
|
||||
continue
|
||||
if k in fixed_simple_logging:
|
||||
if k in derived_logging_keys:
|
||||
continue
|
||||
if k in int_keys:
|
||||
try:
|
||||
@@ -501,11 +526,13 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
if k == "fudai_detail_ui_mode":
|
||||
if val not in ("auto", "legacy", "v2_0"):
|
||||
continue
|
||||
if k == "logging.log_format_mode":
|
||||
if val not in ("simple", "detailed"):
|
||||
continue
|
||||
set_nested_value(cfg, k, val)
|
||||
else:
|
||||
set_nested_value(cfg, k, v)
|
||||
for fixed_key, fixed_value in fixed_simple_logging.items():
|
||||
set_nested_value(cfg, fixed_key, fixed_value)
|
||||
apply_derived_logging_fields()
|
||||
write_config(cfg)
|
||||
return handler._send_json({"ok": True})
|
||||
|
||||
|
||||
@@ -10,6 +10,17 @@ from __future__ import annotations
|
||||
import pytest
|
||||
|
||||
|
||||
class _FakeVar:
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
def get(self):
|
||||
return self.value
|
||||
|
||||
def set(self, value):
|
||||
self.value = value
|
||||
|
||||
|
||||
class TestGetOperationType:
|
||||
"""get_operation_type 纯函数测试。"""
|
||||
|
||||
@@ -202,3 +213,67 @@ class TestGuiComponentsModules:
|
||||
from gui.components import mapping_table
|
||||
|
||||
assert mapping_table is not None
|
||||
|
||||
|
||||
class TestLoggingConfigMode:
|
||||
def _logging_vars(self, mode="simple"):
|
||||
return {
|
||||
"logging_beautify_var": _FakeVar(True),
|
||||
"logging_color_var": _FakeVar(True),
|
||||
"logging_show_timestamps_var": _FakeVar(True),
|
||||
"logging_use_dated_logs_var": _FakeVar(True),
|
||||
"logging_enable_monitor_var": _FakeVar(True),
|
||||
"logging_keep_days_var": _FakeVar(30),
|
||||
"logging_compress_logs_var": _FakeVar(True),
|
||||
"logging_max_total_size_gb_var": _FakeVar(10.0),
|
||||
"logging_compress_after_days_var": _FakeVar(7),
|
||||
"logging_debug_level_var": _FakeVar("normal"),
|
||||
"logging_error_level_var": _FakeVar("full"),
|
||||
"logging_action_format_var": _FakeVar("concise"),
|
||||
"logging_format_mode_var": _FakeVar(mode),
|
||||
"stage_diag_verbose_var": _FakeVar(False),
|
||||
"logging_monitor_warning_mb_var": _FakeVar(500.0),
|
||||
"logging_monitor_critical_mb_var": _FakeVar(2000.0),
|
||||
"logging_performance_enabled_var": _FakeVar(True),
|
||||
"logging_track_functions_var": _FakeVar(True),
|
||||
"log_unified_enabled_var": _FakeVar(True),
|
||||
"log_unified_path_var": _FakeVar("logs/unified.log"),
|
||||
}
|
||||
|
||||
def test_write_logging_to_cfg_derives_detail_fields_from_top_mode(self):
|
||||
from gui.components.config_io_helpers import write_logging_to_cfg
|
||||
|
||||
cfg = {}
|
||||
write_logging_to_cfg(cfg, self._logging_vars("detailed"))
|
||||
|
||||
assert cfg["logging"]["log_format_mode"] == "detailed"
|
||||
assert cfg["logging"]["debug_detail_level"] == "detailed"
|
||||
assert cfg["logging"]["action_log_format"] == "detailed"
|
||||
assert cfg["logging"]["error_detail_level"] == "full"
|
||||
|
||||
def test_apply_logging_from_cfg_normalizes_invalid_mode_to_simple(self):
|
||||
from gui.components.config_io_helpers import apply_logging_from_cfg
|
||||
|
||||
vars_ = self._logging_vars("detailed")
|
||||
apply_logging_from_cfg(vars_, {"logging": {"log_format_mode": "verbose"}})
|
||||
|
||||
assert vars_["logging_format_mode_var"].get() == "simple"
|
||||
assert vars_["logging_debug_level_var"].get() == "normal"
|
||||
assert vars_["logging_action_format_var"].get() == "concise"
|
||||
|
||||
def test_logging_tabs_keep_only_top_mode_control(self):
|
||||
from pathlib import Path
|
||||
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
desktop_src = (root / "gui" / "components" / "logging_tab.py").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
web_src = (root / "webui" / "js" / "config_panel_templates.js").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
|
||||
assert "logging_format_mode_var" in desktop_src
|
||||
assert "logging_log_format_mode" in web_src
|
||||
assert 'id="logging_debug_detail_level"' not in web_src
|
||||
assert 'id="logging_error_detail_level"' not in web_src
|
||||
assert 'id="logging_action_log_format"' not in web_src
|
||||
@@ -94,5 +94,77 @@ def test_simple_keeps_business_summary_and_warnings(capsys):
|
||||
out = capsys.readouterr().out
|
||||
assert "[福袋详情]" in out
|
||||
assert "read_fudai_detail_once完成(成功)" in out
|
||||
assert "倒计时OCR结果完全为空" not in out
|
||||
|
||||
|
||||
def test_simple_keeps_non_noise_warning(capsys):
|
||||
analyser = _analyser()
|
||||
|
||||
enhanced_log_kv(
|
||||
analyser,
|
||||
"设备",
|
||||
"ADB设备连接异常",
|
||||
level="WARNING",
|
||||
)
|
||||
|
||||
out = capsys.readouterr().out
|
||||
assert "[WARNING]" in out
|
||||
assert "倒计时OCR结果完全为空" in out
|
||||
assert "ADB设备连接异常" in out
|
||||
|
||||
|
||||
def test_simple_stdout_uses_short_daily_line(capsys):
|
||||
analyser = _analyser()
|
||||
|
||||
_enhanced_log_kv_simple(
|
||||
analyser,
|
||||
"福袋详情",
|
||||
"read_fudai_detail_once完成(成功)",
|
||||
"INFO",
|
||||
[
|
||||
"[2026-06-03 11:09:30.208]",
|
||||
"[INFO]",
|
||||
"[福袋详情]",
|
||||
"read_fudai_detail_once完成(成功)",
|
||||
"elapsed_seconds=25.1 value_yuan=198",
|
||||
],
|
||||
"2026-06-03 11:09:30.208",
|
||||
{"elapsed_seconds": 25.1, "value_yuan": 198},
|
||||
False,
|
||||
"",
|
||||
)
|
||||
|
||||
out = capsys.readouterr().out.strip()
|
||||
assert out.startswith("[11:09:30] [福袋详情]")
|
||||
assert "[INFO]" not in out
|
||||
assert "2026-06-03" not in out
|
||||
assert "价值=198" in out
|
||||
assert len(out) <= 150
|
||||
|
||||
|
||||
def test_simple_suppresses_ocr_summary_and_validation_noise(capsys):
|
||||
analyser = _analyser()
|
||||
|
||||
_enhanced_log_kv_simple(
|
||||
analyser,
|
||||
"福袋详情",
|
||||
"OCR摘要",
|
||||
"INFO",
|
||||
["[2026-06-03 11:09:30.178]", "[INFO]", "[福袋详情]", "OCR摘要"],
|
||||
"2026-06-03 11:09:30.178",
|
||||
{"_log_type": "OCR_SUMMARY"},
|
||||
False,
|
||||
"",
|
||||
)
|
||||
_enhanced_log_kv_simple(
|
||||
analyser,
|
||||
"福袋倒计时",
|
||||
"分割识别失败(分钟或秒为空)",
|
||||
"INFO",
|
||||
["[2026-06-03 11:09:30.181]", "[INFO]", "[福袋倒计时]", "分割识别失败"],
|
||||
"2026-06-03 11:09:30.181",
|
||||
{},
|
||||
False,
|
||||
"",
|
||||
)
|
||||
|
||||
assert capsys.readouterr().out == ""
|
||||
@@ -157,6 +157,61 @@ def test_config_rejects_invalid_fudai_detail_ui_mode(monkeypatch):
|
||||
assert written["fudai_detail_ui_mode"] == "legacy"
|
||||
|
||||
|
||||
def test_config_log_format_mode_is_single_detail_entry(monkeypatch):
|
||||
written = {}
|
||||
|
||||
monkeypatch.setattr(
|
||||
routes,
|
||||
"read_config",
|
||||
lambda: {
|
||||
"logging": {
|
||||
"log_format_mode": "simple",
|
||||
"debug_detail_level": "normal",
|
||||
"action_log_format": "concise",
|
||||
}
|
||||
},
|
||||
)
|
||||
monkeypatch.setattr(routes, "write_config", lambda cfg: written.update(cfg))
|
||||
|
||||
status, obj = _post(
|
||||
"/api/config",
|
||||
{
|
||||
"config": {
|
||||
"logging.log_format_mode": "detailed",
|
||||
"logging.debug_detail_level": "normal",
|
||||
"logging.action_log_format": "concise",
|
||||
}
|
||||
},
|
||||
monkeypatch,
|
||||
)
|
||||
|
||||
assert status == 200
|
||||
assert obj.get("ok") is True
|
||||
assert written["logging"]["log_format_mode"] == "detailed"
|
||||
assert written["logging"]["debug_detail_level"] == "detailed"
|
||||
assert written["logging"]["action_log_format"] == "detailed"
|
||||
assert written["logging"]["error_detail_level"] == "full"
|
||||
|
||||
|
||||
def test_config_rejects_invalid_log_format_mode(monkeypatch):
|
||||
written = {}
|
||||
|
||||
monkeypatch.setattr(routes, "read_config", lambda: {"logging": {"log_format_mode": "simple"}})
|
||||
monkeypatch.setattr(routes, "write_config", lambda cfg: written.update(cfg))
|
||||
|
||||
status, obj = _post(
|
||||
"/api/config",
|
||||
{"config": {"logging.log_format_mode": "verbose"}},
|
||||
monkeypatch,
|
||||
)
|
||||
|
||||
assert status == 200
|
||||
assert obj.get("ok") is True
|
||||
assert written["logging"]["log_format_mode"] == "simple"
|
||||
assert written["logging"]["debug_detail_level"] == "normal"
|
||||
assert written["logging"]["action_log_format"] == "concise"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"ports_raw,expected_invalid",
|
||||
[
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
"logging.compress_logs",
|
||||
"logging.enable_monitor",
|
||||
"logging.keep_days",
|
||||
"logging.log_format_mode",
|
||||
"logging.max_total_size_gb",
|
||||
"logging.monitor_critical_mb",
|
||||
"logging.monitor_warning_mb",
|
||||
@@ -154,7 +155,6 @@
|
||||
"logging.action_log_format",
|
||||
"logging.debug_detail_level",
|
||||
"logging.error_detail_level",
|
||||
"logging.log_format_mode",
|
||||
"logging.use_dated_logs"
|
||||
],
|
||||
"gui_saved_keys": [
|
||||
@@ -528,6 +528,7 @@
|
||||
"logging.compress_logs",
|
||||
"logging.enable_monitor",
|
||||
"logging.keep_days",
|
||||
"logging.log_format_mode",
|
||||
"logging.max_total_size_gb",
|
||||
"logging.monitor_critical_mb",
|
||||
"logging.monitor_warning_mb",
|
||||
|
||||
@@ -49,11 +49,10 @@ GUI_RUNTIME_ONLY_KEYS = {
|
||||
# These are right-side runtime refresh preferences in gui_app.py.
|
||||
"gui.realtime_status.refresh_interval_ms",
|
||||
"gui.realtime_status.tail_items",
|
||||
# Internal compatibility fields: UI always uses simple mode now.
|
||||
# Internal compatibility fields: UI derives these from logging.log_format_mode.
|
||||
"logging.debug_detail_level",
|
||||
"logging.error_detail_level",
|
||||
"logging.action_log_format",
|
||||
"logging.log_format_mode",
|
||||
}
|
||||
|
||||
FUDAI_DETAIL_OCR_KEYS = {
|
||||
|
||||
@@ -259,25 +259,12 @@
|
||||
<input id="logging_max_total_size_gb" class="input" data-key="logging.max_total_size_gb" data-type="float" type="number" min="0" step="0.5" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row grid2">
|
||||
<div>
|
||||
<label class="label">调试日志级别</label>
|
||||
<div class="hint">固定为 normal;simple 会自动隐藏调试噪声</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">错误日志级别</label>
|
||||
<div class="hint">固定为 full;错误和异常仍完整保留</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row grid2">
|
||||
<div>
|
||||
<label class="label">行为日志格式</label>
|
||||
<div class="hint">固定为 concise,日常日志统一走 simple 简洁模式</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">日志格式模式</label>
|
||||
<div class="hint">固定为 simple,调试细节自动收进 debug/detail</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label class="label">日志格式模式</label>
|
||||
<select id="logging_log_format_mode" class="input" data-key="logging.log_format_mode" data-type="str">
|
||||
<option value="simple">simple</option><option value="detailed">detailed</option>
|
||||
</select>
|
||||
<div class="hint">唯一日志详细度入口:simple=日常极简,detailed=调试详细;调试/错误/行为详细度自动跟随</div>
|
||||
</div>
|
||||
<div class="row grid3">
|
||||
<div>
|
||||
|
||||
Reference in new issue
Block a user