diff --git a/config/config.json b/config/config.json index 1ad5d73..8b1fa79 100644 --- a/config/config.json +++ b/config/config.json @@ -46,7 +46,7 @@ "yanghao_comment_prob": 1.0, "yanghao_icon_roi_size": 240, "yanghao_icon_match_threshold": 0.77, - "yanghao_step_screenshot": false, + "yanghao_step_screenshot": true, "yanghao_like_roi_offset_x": 0, "yanghao_like_roi_offset_y": -50, "yanghao_like_roi_scale": 1.0, @@ -69,8 +69,8 @@ "fudai_quiet_hours_enabled": true, "fudai_quiet_start_hour": 2, "fudai_quiet_end_hour": 9, - "yanghao_enabled": false, - "yanghao_enable_actions": false, + "yanghao_enabled": true, + "yanghao_enable_actions": true, "yanghao_like_icon_x": 988, "yanghao_like_icon_y": 1218, "yanghao_fav_icon_x": 988, @@ -213,7 +213,7 @@ "fansclub_auto_join_wait_seconds": 5.0, "fansclub_manual_wait_seconds": 3.0, "enable_streaming_screenshot": false, - "yanghao_only": false, + "yanghao_only": true, "record_room_title_mapping_enabled": true, "high_value_fudai_poll_before_seconds": 10.0, "high_value_room_revisit_min_interval_seconds": 300, diff --git a/requirements.txt b/requirements.txt index 1c32605..f779371 100644 --- a/requirements.txt +++ b/requirements.txt @@ -35,13 +35,8 @@ ttkbootstrap>=1.10.0 # Web GUI测试工具(如果需要使用Web界面测试功能) # playwright>=1.30.0 -# 注意: -# 1. 如果paddlepaddle安装失败,可以尝试: -# CPU版本: pip install paddlepaddle==2.5.2 -i https://pypi.tuna.tsinghua.edu.cn/simple -# GPU版本: pip install paddlepaddle-gpu==2.5.2 -i https://pypi.tuna.tsinghua.edu.cn/simple -# -# 2. 如果网络连接有问题,可以使用国内镜像源: -# pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple +# 终端颜色输出(用于彩色日志查看器) +colorama>=0.4.0 diff --git a/tools/README_color_log_viewer.md b/tools/README_color_log_viewer.md new file mode 100644 index 0000000..17bc9ff --- /dev/null +++ b/tools/README_color_log_viewer.md @@ -0,0 +1,88 @@ +# 彩色日志查看器使用说明 + +## 概述 +`color_log_viewer.py` 是一个彩色日志查看工具,为不同类型的日志操作分配不同颜色,便于快速识别和分析日志内容。 + +## 颜色映射 +- **流程**: 青色 - 程序流程相关日志 +- **阶段**: 蓝色 - 程序阶段相关日志 +- **参与**: 绿色 - 福袋参与相关日志 +- **预约**: 黄色 - 预约系统相关日志 +- **识别**: 品红 - 图像识别相关日志 +- **OCR**: 红色 - OCR识别相关日志 +- **截图**: 亮红 - 截图操作相关日志 +- **错误**: 亮红 - 错误信息 +- **警告**: 亮黄 - 警告信息 +- **异常**: 红底黄字 - 异常信息 +- **统计**: 亮青 - 统计信息 +- **效率**: 亮绿 - 效率统计 +- **默认**: 灰色 - 其他日志 + +## 使用方法 + +### 基本用法 +```bash +# 查看整个日志文件(默认显示前50行) +python tools/color_log_viewer.py logs/actions.log + +# 筛选特定关键字 +python tools/color_log_viewer.py logs/actions.log "参与成功" + +# 查看unified日志 +python tools/color_log_viewer.py logs/unified_20260112.log "流程" +``` + +### 高级选项 +```bash +# 限制显示行数 +python tools/color_log_viewer.py logs/actions.log --lines 20 + +# 显示所有匹配行(不限制数量) +python tools/color_log_viewer.py logs/actions.log "错误" --all + +# 组合使用 +python tools/color_log_viewer.py logs/actions.log "参与成功" --lines 100 +``` + +## 示例输出 +运行 `python tools/color_log_viewer.py logs/actions.log "参与成功" --lines 5` 会显示: + +``` +日志颜色图例: +======================================== +[流程] - 流程相关日志 +[参与] - 参与相关日志 +... + +正在读取日志文件: logs/actions.log +过滤关键字: 参与成功 +总行数: 10171 +显示行数: 536 +================================================================================ + +[2026-01-12 18:01:59.850] [参与] basic_join_decision:参与成功 +[2026-01-12 18:02:21.698] [参与] 参与成功,但倒计时已过期,不设置等待标志 +... + +================================================================================ +显示完成 (显示 5/536 行) +``` + +## 日志格式要求 +工具期望的日志格式为: +``` +[时间戳] [标签] 消息内容 +``` + +例如: +``` +[2026-01-12 18:01:59.850] [参与] basic_join_decision:参与成功 +``` + +## 依赖 +需要安装 `colorama` 库: +```bash +pip install colorama +``` + +已在 `requirements.txt` 中添加此依赖。 \ No newline at end of file diff --git a/tools/color_log_viewer.py b/tools/color_log_viewer.py new file mode 100644 index 0000000..12cfa83 --- /dev/null +++ b/tools/color_log_viewer.py @@ -0,0 +1,180 @@ +#!/usr/bin/env python3 +""" +彩色日志查看器 +为不同类型的日志操作分配不同颜色,便于观看和分析 + +用法: python color_log_viewer.py <日志文件路径> [过滤关键字] +示例: python color_log_viewer.py logs/actions.log + python color_log_viewer.py logs/actions.log "参与" +""" + +import sys +import re +from pathlib import Path +from colorama import init, Fore, Back, Style + +# 初始化colorama(自动重置颜色) +init(autoreset=True) + +# 定义颜色映射(根据日志标签分配颜色) +COLOR_MAP = { + # 流程相关 + '流程': Fore.CYAN, + '阶段': Fore.BLUE, + + # 参与相关 + '参与': Fore.GREEN, + '预约': Fore.YELLOW, + + # 识别相关 + '识别': Fore.MAGENTA, + 'OCR': Fore.RED, + '截图': Fore.LIGHTRED_EX, + + # 福袋查找相关 + '福袋查找': Fore.LIGHTBLUE_EX, + + # 错误和警告 + '错误': Fore.RED + Style.BRIGHT, + '警告': Fore.YELLOW + Style.BRIGHT, + '异常': Fore.RED + Back.YELLOW, + + # 统计相关 + '统计': Fore.LIGHTCYAN_EX, + '效率': Fore.LIGHTGREEN_EX, + + # 默认颜色 + 'default': Fore.WHITE, +} + +# 正则表达式匹配日志行格式 +LOG_PATTERN = re.compile(r'^\[([^\]]+)\]\s*\[([^\]]+)\]\s*(.*)$') + + +def get_color_for_tag(tag): + """根据标签获取颜色 + 规则:先精确匹配,再前缀匹配(用于嵌套标签前缀),否则返回默认颜色。 + """ + if tag in COLOR_MAP: + return COLOR_MAP[tag] + + for key in COLOR_MAP: + if key != 'default' and tag.startswith(key): + return COLOR_MAP[key] + + return COLOR_MAP['default'] + + +def colorize_log_line(line): + """为日志行添加颜色""" + match = LOG_PATTERN.match(line.strip()) + if match: + timestamp, tag, message = match.groups() + # 优先根据主标签匹配颜色 + color = get_color_for_tag(tag) + + # 如果主标签为默认颜色,尝试从 message 中提取第一个方括号子标签再匹配一次 + if color == COLOR_MAP['default']: + inner_bracket = re.search(r"\[([^\]]+)\]", message) + if inner_bracket: + inner_tag = inner_bracket.group(1).strip() + color = get_color_for_tag(inner_tag) + + return f"{Fore.LIGHTBLACK_EX}[{timestamp}]{Style.RESET_ALL} {color}[{tag}]{Style.RESET_ALL} {message}" + else: + # 非标准格式的行,使用默认颜色 + return f"{Fore.LIGHTBLACK_EX}{line}{Style.RESET_ALL}" + +def filter_and_colorize_log(log_file_path, filter_keyword=None, max_lines=50): + """ + 读取日志文件,筛选并彩色化输出 + + Args: + log_file_path: 日志文件路径 + filter_keyword: 过滤关键字(可选) + max_lines: 最大显示行数(默认50) + """ + log_path = Path(log_file_path) + if not log_path.exists(): + print(f"{Fore.RED}错误: 日志文件不存在: {log_file_path}{Style.RESET_ALL}") + return + + print(f"{Fore.CYAN}正在读取日志文件: {log_file_path}{Style.RESET_ALL}") + if filter_keyword: + print(f"{Fore.CYAN}过滤关键字: {filter_keyword}{Style.RESET_ALL}") + + try: + with open(log_path, 'r', encoding='utf-8', errors='ignore') as f: + lines = f.readlines() + + total_lines = len(lines) + filtered_lines = [] + + # 如果有过滤关键字,先筛选 + if filter_keyword: + pattern = re.compile(filter_keyword, re.IGNORECASE) + filtered_lines = [line for line in lines if pattern.search(line)] + else: + filtered_lines = lines + + print(f"{Fore.GREEN}总行数: {total_lines}{Style.RESET_ALL}") + print(f"{Fore.GREEN}显示行数: {len(filtered_lines)}{Style.RESET_ALL}") + print(f"{Fore.YELLOW}{'='*80}{Style.RESET_ALL}") + print() + + # 显示彩色化的日志 + displayed_count = 0 + for line in filtered_lines: + if line.strip(): # 跳过空行 + if max_lines is None or displayed_count < max_lines: + colored_line = colorize_log_line(line) + print(colored_line) + displayed_count += 1 + else: + break + + if max_lines is not None and len(filtered_lines) > max_lines: + print(f"\n{Fore.YELLOW}... 还有 {len(filtered_lines) - max_lines} 行未显示 (使用 --all 参数查看全部){Style.RESET_ALL}") + + print() + print(f"{Fore.YELLOW}{'='*80}{Style.RESET_ALL}") + print(f"{Fore.GREEN}显示完成 (显示 {displayed_count}/{len(filtered_lines)} 行){Style.RESET_ALL}") + + except Exception as e: + print(f"{Fore.RED}错误: 读取文件时出错: {e}{Style.RESET_ALL}") + +def show_color_legend(): + """显示颜色图例""" + print(f"{Fore.CYAN}日志颜色图例:{Style.RESET_ALL}") + print(f"{Fore.CYAN}{'='*40}{Style.RESET_ALL}") + for tag, color in COLOR_MAP.items(): + if tag != 'default': + print(f"{color}[{tag}]{Style.RESET_ALL} - {tag}相关日志") + print(f"{Fore.LIGHTBLACK_EX}[默认]{Style.RESET_ALL} - 其他日志") + print() + +def main(): + import argparse + + parser = argparse.ArgumentParser(description='彩色日志查看器') + parser.add_argument('log_file', help='日志文件路径') + parser.add_argument('filter_keyword', nargs='?', help='过滤关键字(可选)') + parser.add_argument('--lines', type=int, default=50, help='最大显示行数(默认50)') + parser.add_argument('--all', action='store_true', help='显示所有行(忽略--lines限制)') + + args = parser.parse_args() + + log_file = args.log_file + filter_keyword = args.filter_keyword + max_lines = None if args.all else args.lines + + # 如果是相对路径,相对于项目根目录 + if not Path(log_file).is_absolute(): + project_root = Path(__file__).parent.parent + log_file = str(project_root / log_file) + + show_color_legend() + filter_and_colorize_log(log_file, filter_keyword, max_lines) + +if __name__ == "__main__": + main() \ No newline at end of file