feat: 添加日志监控阈值配置选项,优化日志管理功能
This commit is contained in:
1 parent
917438af2e
commit
2c9513ebd4
3 files changed
+158
-6
No files matched your search
+4
-4
@@ -176,13 +176,13 @@
|
||||
]
|
||||
},
|
||||
"compress_logs": true,
|
||||
"max_total_size_gb": 10.0,
|
||||
"compress_after_days": 7,
|
||||
"max_total_size_gb": 0.5,
|
||||
"compress_after_days": 3,
|
||||
"max_bytes": 104857600,
|
||||
"backup_count": 10,
|
||||
"enable_monitor": true,
|
||||
"monitor_warning_mb": 500.0,
|
||||
"monitor_critical_mb": 2000.0
|
||||
"monitor_critical_mb": 500.0
|
||||
},
|
||||
"debug_captures": {
|
||||
"enabled": false,
|
||||
@@ -210,4 +210,4 @@
|
||||
"yanghao_only": false,
|
||||
"record_room_title_mapping_enabled": true,
|
||||
"enable_back_on_misses": true
|
||||
}
|
||||
}
|
||||
@@ -468,8 +468,12 @@ def _load_logging_cleanup_policy_from_config() -> tuple[int, float, int, bool]:
|
||||
log_cfg = cfg.get("logging", {})
|
||||
if isinstance(log_cfg, dict):
|
||||
keep_days = int(log_cfg.get("keep_days", keep_days))
|
||||
max_total_size_gb = float(log_cfg.get("max_total_size_gb", max_total_size_gb))
|
||||
compress_after_days = int(log_cfg.get("compress_after_days", compress_after_days))
|
||||
max_total_size_gb = float(
|
||||
log_cfg.get("max_total_size_gb", max_total_size_gb)
|
||||
)
|
||||
compress_after_days = int(
|
||||
log_cfg.get("compress_after_days", compress_after_days)
|
||||
)
|
||||
compress = bool(log_cfg.get("compress_logs", compress))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
+148
@@ -627,6 +627,21 @@ def main():
|
||||
logging_show_timestamps_var = tk.BooleanVar(
|
||||
value=bool(cfg.get("logging", {}).get("show_timestamps", True))
|
||||
)
|
||||
logging_enable_monitor_var = tk.BooleanVar(
|
||||
value=bool(cfg.get("logging", {}).get("enable_monitor", True))
|
||||
)
|
||||
logging_keep_days_var = tk.IntVar(
|
||||
value=int(cfg.get("logging", {}).get("keep_days", 30) or 30)
|
||||
)
|
||||
logging_compress_logs_var = tk.BooleanVar(
|
||||
value=bool(cfg.get("logging", {}).get("compress_logs", True))
|
||||
)
|
||||
logging_max_total_size_gb_var = tk.DoubleVar(
|
||||
value=float(cfg.get("logging", {}).get("max_total_size_gb", 10.0) or 10.0)
|
||||
)
|
||||
logging_compress_after_days_var = tk.IntVar(
|
||||
value=int(cfg.get("logging", {}).get("compress_after_days", 7) or 7)
|
||||
)
|
||||
logging_performance_enabled_var = tk.BooleanVar(
|
||||
value=bool(
|
||||
cfg.get("logging", {}).get("performance_tracking", {}).get("enabled", True)
|
||||
@@ -648,6 +663,14 @@ def main():
|
||||
logging_action_format_var = tk.StringVar(
|
||||
value=str(cfg.get("logging", {}).get("action_log_format", "concise"))
|
||||
)
|
||||
logging_monitor_warning_mb_var = tk.DoubleVar(
|
||||
value=float(cfg.get("logging", {}).get("monitor_warning_mb", 500.0) or 500.0)
|
||||
)
|
||||
logging_monitor_critical_mb_var = tk.DoubleVar(
|
||||
value=float(
|
||||
cfg.get("logging", {}).get("monitor_critical_mb", 2000.0) or 2000.0
|
||||
)
|
||||
)
|
||||
# GUI 主题变量
|
||||
gui_theme_var = tk.StringVar(
|
||||
value=str(cfg.get("gui", {}).get("theme", "litera") or "litera")
|
||||
@@ -1460,6 +1483,20 @@ def main():
|
||||
variable=logging_color_var,
|
||||
).pack(side=LEFT, padx=(20, 0))
|
||||
|
||||
# 监控与清理开关
|
||||
log_r1b = ttk.Frame(logging_config_box)
|
||||
log_r1b.pack(fill=X, padx=10, pady=(0, 6))
|
||||
ttk.Checkbutton(
|
||||
log_r1b,
|
||||
text="启用日志监控(超限告警/触发清理)",
|
||||
variable=logging_enable_monitor_var,
|
||||
).pack(side=LEFT)
|
||||
ttk.Checkbutton(
|
||||
log_r1b,
|
||||
text="压缩旧日志",
|
||||
variable=logging_compress_logs_var,
|
||||
).pack(side=LEFT, padx=(20, 0))
|
||||
|
||||
# 日志详细程度
|
||||
log_r2 = ttk.Frame(logging_config_box)
|
||||
log_r2.pack(fill=X, padx=10, pady=(0, 6))
|
||||
@@ -1534,6 +1571,59 @@ def main():
|
||||
variable=streaming_enabled_var,
|
||||
).pack(side=LEFT, padx=(20, 0), pady=5)
|
||||
|
||||
# 清理策略参数
|
||||
log_r4b = ttk.Frame(logging_config_box)
|
||||
log_r4b.pack(fill=X, padx=10, pady=(0, 10))
|
||||
ttk.Label(log_r4b, text="保留天数:").pack(side=LEFT)
|
||||
ttk.Spinbox(
|
||||
log_r4b,
|
||||
from_=1,
|
||||
to=365,
|
||||
increment=1,
|
||||
textvariable=logging_keep_days_var,
|
||||
width=6,
|
||||
).pack(side=LEFT, padx=(6, 16))
|
||||
ttk.Label(log_r4b, text="总量上限(GB):").pack(side=LEFT)
|
||||
ttk.Spinbox(
|
||||
log_r4b,
|
||||
from_=0.1,
|
||||
to=100.0,
|
||||
increment=0.1,
|
||||
textvariable=logging_max_total_size_gb_var,
|
||||
width=8,
|
||||
).pack(side=LEFT, padx=(6, 16))
|
||||
ttk.Label(log_r4b, text="压缩阈值(天):").pack(side=LEFT)
|
||||
ttk.Spinbox(
|
||||
log_r4b,
|
||||
from_=0,
|
||||
to=365,
|
||||
increment=1,
|
||||
textvariable=logging_compress_after_days_var,
|
||||
width=6,
|
||||
).pack(side=LEFT, padx=(6, 0))
|
||||
|
||||
# 日志监控阈值(也用于触发自动清理)
|
||||
log_r5 = ttk.Frame(logging_config_box)
|
||||
log_r5.pack(fill=X, padx=10, pady=(0, 10))
|
||||
ttk.Label(log_r5, text="日志总大小警告阈值(MB):").pack(side=LEFT)
|
||||
ttk.Spinbox(
|
||||
log_r5,
|
||||
from_=50,
|
||||
to=20000,
|
||||
increment=50,
|
||||
textvariable=logging_monitor_warning_mb_var,
|
||||
width=8,
|
||||
).pack(side=LEFT, padx=(6, 16))
|
||||
ttk.Label(log_r5, text="严重阈值(MB):").pack(side=LEFT)
|
||||
ttk.Spinbox(
|
||||
log_r5,
|
||||
from_=100,
|
||||
to=100000,
|
||||
increment=100,
|
||||
textvariable=logging_monitor_critical_mb_var,
|
||||
width=8,
|
||||
).pack(side=LEFT, padx=(6, 0))
|
||||
|
||||
# 标签页6:关键词
|
||||
keywords_tab = ttk.Frame(left_notebook)
|
||||
left_notebook.add(keywords_tab, text="关键词")
|
||||
@@ -1720,6 +1810,49 @@ def main():
|
||||
debug_captures_keep_days_var.set(7)
|
||||
debug_captures_max_files_var.set(2000)
|
||||
|
||||
# 日志配置(load_config_to_ui 需要覆盖 UI 变量,避免“保存后再加载不生效”)
|
||||
logging_config = cfg.get("logging", {})
|
||||
if isinstance(logging_config, dict):
|
||||
logging_beautify_var.set(bool(logging_config.get("beautify_output", True)))
|
||||
logging_color_var.set(bool(logging_config.get("color_output", True)))
|
||||
logging_show_timestamps_var.set(
|
||||
bool(logging_config.get("show_timestamps", True))
|
||||
)
|
||||
logging_enable_monitor_var.set(
|
||||
bool(logging_config.get("enable_monitor", True))
|
||||
)
|
||||
logging_keep_days_var.set(int(logging_config.get("keep_days", 30) or 30))
|
||||
logging_compress_logs_var.set(
|
||||
bool(logging_config.get("compress_logs", True))
|
||||
)
|
||||
logging_max_total_size_gb_var.set(
|
||||
float(logging_config.get("max_total_size_gb", 10.0) or 10.0)
|
||||
)
|
||||
logging_compress_after_days_var.set(
|
||||
int(logging_config.get("compress_after_days", 7) or 7)
|
||||
)
|
||||
logging_debug_level_var.set(
|
||||
str(logging_config.get("debug_detail_level", "normal") or "normal")
|
||||
)
|
||||
logging_error_level_var.set(
|
||||
str(logging_config.get("error_detail_level", "full") or "full")
|
||||
)
|
||||
logging_action_format_var.set(
|
||||
str(logging_config.get("action_log_format", "concise") or "concise")
|
||||
)
|
||||
perf_cfg = logging_config.get("performance_tracking", {})
|
||||
if isinstance(perf_cfg, dict):
|
||||
logging_performance_enabled_var.set(bool(perf_cfg.get("enabled", True)))
|
||||
logging_track_functions_var.set(
|
||||
bool(perf_cfg.get("track_function_calls", True))
|
||||
)
|
||||
logging_monitor_warning_mb_var.set(
|
||||
float(logging_config.get("monitor_warning_mb", 500.0) or 500.0)
|
||||
)
|
||||
logging_monitor_critical_mb_var.set(
|
||||
float(logging_config.get("monitor_critical_mb", 2000.0) or 2000.0)
|
||||
)
|
||||
|
||||
yg_like_prob_var.set(float(cfg.get("yanghao_like_prob", 0.0) or 0.0))
|
||||
yg_fav_prob_var.set(float(cfg.get("yanghao_fav_prob", 0.0) or 0.0))
|
||||
yg_comment_prob_var.set(float(cfg.get("yanghao_comment_prob", 0.0) or 0.0))
|
||||
@@ -1939,6 +2072,15 @@ def main():
|
||||
cfg2["logging"]["beautify_output"] = bool(logging_beautify_var.get())
|
||||
cfg2["logging"]["color_output"] = bool(logging_color_var.get())
|
||||
cfg2["logging"]["show_timestamps"] = bool(logging_show_timestamps_var.get())
|
||||
cfg2["logging"]["enable_monitor"] = bool(logging_enable_monitor_var.get())
|
||||
cfg2["logging"]["keep_days"] = int(logging_keep_days_var.get() or 30)
|
||||
cfg2["logging"]["compress_logs"] = bool(logging_compress_logs_var.get())
|
||||
cfg2["logging"]["max_total_size_gb"] = float(
|
||||
logging_max_total_size_gb_var.get() or 10.0
|
||||
)
|
||||
cfg2["logging"]["compress_after_days"] = int(
|
||||
logging_compress_after_days_var.get() or 7
|
||||
)
|
||||
cfg2["logging"]["debug_detail_level"] = str(
|
||||
logging_debug_level_var.get() or "normal"
|
||||
)
|
||||
@@ -1948,6 +2090,12 @@ def main():
|
||||
cfg2["logging"]["action_log_format"] = str(
|
||||
logging_action_format_var.get() or "concise"
|
||||
)
|
||||
cfg2["logging"]["monitor_warning_mb"] = float(
|
||||
logging_monitor_warning_mb_var.get() or 500.0
|
||||
)
|
||||
cfg2["logging"]["monitor_critical_mb"] = float(
|
||||
logging_monitor_critical_mb_var.get() or 2000.0
|
||||
)
|
||||
|
||||
# 性能追踪配置
|
||||
if "performance_tracking" not in cfg2["logging"] or not isinstance(
|
||||
|
||||
Reference in new issue
Block a user