log-reader
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMT5 Log Reader
MT5 日志读取器
Read MetaTrader 5 log files directly to access Print() output from indicators, scripts, and expert advisors without requiring manual Experts pane inspection.
直接读取MetaTrader 5日志文件,无需手动查看专家面板(Experts pane),即可获取指标、脚本和专家顾问的Print()输出。
Purpose
用途
Implement "Option 3" dual logging pattern:
- Print() - MT5 log files (human-readable via Experts pane)
- CSV files - Structured data (programmatic analysis)
Claude Code CLI can autonomously read both outputs without user intervention.
实现「方案3」双日志模式:
- Print() - MT5日志文件(可通过Experts pane查看,便于人类阅读)
- CSV文件 - 结构化数据(用于程序化分析)
Claude Code CLI无需用户干预即可自动读取这两种输出。
When to Use This Skill
何时使用该技能
Use this skill when:
- Validating MT5 indicator/script execution
- Checking compilation or runtime errors
- Analyzing Print() debug output
- Verifying unit test results (Test_PatternDetector, Test_ArrowManager)
- User mentions checking "Experts pane" manually
在以下场景中使用本技能:
- 验证MT5指标/脚本的执行情况
- 检查编译或运行时错误
- 分析Print()调试输出
- 验证单元测试结果(Test_PatternDetector、Test_ArrowManager)
- 用户提及手动查看「Experts pane」
Log File Location
日志文件位置
MT5 logs are stored at:
$MQL5_ROOT/Program Files/MetaTrader 5/MQL5/Logs/YYYYMMDD.logFile Format:
- Encoding: UTF-16LE (Little Endian)
- Structure: Tab-separated fields (timestamp, source, message)
- Size: Grows throughout day (typically 10-100KB)
MT5日志存储在:
$MQL5_ROOT/Program Files/MetaTrader 5/MQL5/Logs/YYYYMMDD.log文件格式:
- 编码:UTF-16LE(小端序)
- 结构:制表符分隔字段(时间戳、来源、消息)
- 大小:全天持续增长(通常为10-100KB)
Instructions
操作步骤
1. Construct today's log path
1. 构造当日日志路径
bash
/usr/bin/env bash << 'SKILL_SCRIPT_EOF'bash
/usr/bin/env bash << 'SKILL_SCRIPT_EOF'Determine current date
Determine current date
TODAY=$(date +"%Y%m%d")
TODAY=$(date +"%Y%m%d")
Build absolute path
Build absolute path
LOG_FILE="$MQL5_ROOT/Program Files/MetaTrader 5/MQL5/Logs/${TODAY}.log"
SKILL_SCRIPT_EOF
undefinedLOG_FILE="$MQL5_ROOT/Program Files/MetaTrader 5/MQL5/Logs/${TODAY}.log"
SKILL_SCRIPT_EOF
undefined2. Read the entire log file
2. 读取完整日志文件
Use Read tool:
- File path: Absolute path from step 1
- The file contains all Print() statements from MT5 indicators/scripts
- UTF-16LE encoding is automatically handled by Read tool
使用Read工具:
- 文件路径:步骤1中生成的绝对路径
- 该文件包含MT5指标/脚本的所有Print()语句
- Read工具会自动处理UTF-16LE编码
3. Search for specific content (optional)
3. 搜索特定内容(可选)
Use Grep to filter entries:
Pattern: indicator name, "error", "test.*passed", etc.
Path: Log file path from step 1
Output mode: "content" with -n (line numbers)
Context: -A 5 for 5 lines after matches使用Grep过滤条目:
Pattern: indicator name, "error", "test.*passed", etc.
Path: Log file path from step 1
Output mode: "content" with -n (line numbers)
Context: -A 5 for 5 lines after matches4. Analyze recent entries (optional)
4. 分析最新条目(可选)
Use Bash with tail for latest output:
bash
tail -n 50 "$LOG_FILE"使用Bash的tail命令查看最新输出:
bash
tail -n 50 "$LOG_FILE"Common Validation Patterns
常见验证模式
Check unit test results
检查单元测试结果
Search for test pass/fail indicators:
Pattern: test.*passed|test.*failed|Tests Passed|Tests Failed|ALL TESTS PASSED
Output mode: content
Context: -B 2 -A 2搜索测试通过/失败标识:
Pattern: test.*passed|test.*failed|Tests Passed|Tests Failed|ALL TESTS PASSED
Output mode: content
Context: -B 2 -A 2Find compilation errors
查找编译错误
Pattern: error|ERROR|warning|WARNING|failed to create
Output mode: content
Context: -A 3Pattern: error|ERROR|warning|WARNING|failed to create
Output mode: content
Context: -A 3Monitor specific indicator
监控特定指标
Pattern: CCI Rising Test|PatternDetector|ArrowManager
Output mode: content
Context: -A 2Pattern: CCI Rising Test|PatternDetector|ArrowManager
Output mode: content
Context: -A 2View initialization messages
查看初始化消息
Pattern: OnInit|initialization|Initialization complete|Phase \d+
Output mode: contentPattern: OnInit|initialization|Initialization complete|Phase \d+
Output mode: contentExamples
示例
Example 1: Validate unit test completion
示例1:验证单元测试完成情况
Input: User compiled Test_PatternDetector.mq5
Action:
1. Read today's log file
2. Grep for "Test.*PatternDetector|Tests Passed|Tests Failed"
3. Report results (e.g., "17 tests passed, 0 failed")
Output: Test status without user checking Experts paneInput: User compiled Test_PatternDetector.mq5
Action:
1. Read today's log file
2. Grep for "Test.*PatternDetector|Tests Passed|Tests Failed"
3. Report results (e.g., "17 tests passed, 0 failed")
Output: Test status without user checking Experts paneExample 2: Check for runtime errors
示例2:检查运行时错误
Input: User reports indicator not working
Action:
1. Read today's log file
2. Grep for "ERROR|error|failed" with -A 3 context
3. Analyze error messages
Output: Specific error details and line numbersInput: User reports indicator not working
Action:
1. Read today's log file
2. Grep for "ERROR|error|failed" with -A 3 context
3. Analyze error messages
Output: Specific error details and line numbersExample 3: Verify Phase 2 arrow creation
示例3:验证Phase 2箭头创建情况
Input: User asks "did the test arrow get created?"
Action:
1. Read today's log file
2. Grep for "Phase 2|Test arrow created|Failed to create"
3. Check for success/failure messages
Output: Arrow creation status with timestampInput: User asks "did the test arrow get created?"
Action:
1. Read today's log file
2. Grep for "Phase 2|Test arrow created|Failed to create"
3. Check for success/failure messages
Output: Arrow creation status with timestampSecurity Considerations
安全注意事项
- Log files may contain sensitive trading data (symbol names, account info)
- Restricted to Read, Bash, Grep tools only (no network access via WebFetch)
- Do not expose absolute paths unnecessarily in user-facing output
- Filter sensitive information when reporting results
- No file modification operations allowed
- 日志文件可能包含敏感交易数据(品种名称、账户信息)
- 仅允许使用Read、Bash、Grep工具(禁止通过WebFetch访问网络)
- 不要在面向用户的输出中不必要地暴露绝对路径
- 报告结果时过滤敏感信息
- 不允许执行任何文件修改操作
Integration with Dual Logging
与双日志模式的集成
This skill enables programmatic access to one half of the dual logging pattern:
- MT5 Log Files (this skill) - Human-readable Print() output
- CSV Files (CSVLogger.mqh) - Structured audit trails for validation
Both are accessible without user intervention:
- MT5 logs: Read via this skill
- CSV files: Read directly via Read tool or validate_export.py
本技能支持程序化访问双日志模式的其中一部分:
- MT5日志文件(本技能)- 便于人类阅读的Print()输出
- CSV文件(CSVLogger.mqh)- 用于验证的结构化审计跟踪
无需用户干预即可访问这两种输出:
- MT5日志:通过本技能读取
- CSV文件:直接通过Read工具或validate_export.py读取
Validation Checklist
验证检查清单
When using this skill:
- Log file exists for today's date
- File size > 0 (not empty)
- Contains expected indicator/script output
- Timestamps match execution time
- Error messages (if any) are actionable
- Test results (if applicable) show pass/fail counts
使用本技能时需确认:
- 当日日志文件存在
- 文件大小>0(非空)
- 包含预期的指标/脚本输出
- 时间戳与执行时间匹配
- 错误消息(若有)可执行
- 测试结果(若适用)显示通过/失败计数
References
参考资料
- MT5 file locations:
docs/guides/MT5_FILE_LOCATIONS.md - Dual logging implementation: Phase 3-4
docs/plans/cci-rising-pattern-marker.yaml - CSVLogger library:
Program Files/MetaTrader 5/MQL5/Indicators/Custom/Development/CCINeutrality/lib/CSVLogger.mqh
- MT5文件位置:
docs/guides/MT5_FILE_LOCATIONS.md - 双日志模式实现:第3-4阶段
docs/plans/cci-rising-pattern-marker.yaml - CSVLogger库:
Program Files/MetaTrader 5/MQL5/Indicators/Custom/Development/CCINeutrality/lib/CSVLogger.mqh
Troubleshooting
故障排除
| Issue | Cause | Solution |
|---|---|---|
| Log file not found | Wrong date or path | Verify YYYYMMDD.log format and MQL5_ROOT env var |
| Empty log file | MT5 not running or no output | Ensure MT5 is running and Print() is being called |
| Encoding errors | UTF-16LE not handled | Read tool handles encoding automatically |
| Missing test results | Test not executed | Compile and run test script in MT5 first |
| Grep finds nothing | Wrong pattern | Use case-insensitive (-i) or broader pattern |
| Old log data | Log rotation | Each day creates new YYYYMMDD.log file |
| Path contains spaces | Unquoted path variable | Quote paths: "$LOG_FILE" |
| Sensitive data exposed | Trading info in logs | Filter sensitive fields when reporting to user |
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 未找到日志文件 | 日期或路径错误 | 验证YYYYMMDD.log格式及MQL5_ROOT环境变量 |
| 日志文件为空 | MT5未运行或无输出 | 确保MT5正在运行且调用了Print()函数 |
| 编码错误 | 未处理UTF-16LE编码 | Read工具会自动处理编码 |
| 缺少测试结果 | 未执行测试 | 先在MT5中编译并运行测试脚本 |
| Grep未找到匹配内容 | 模式错误 | 使用不区分大小写(-i)或更宽泛的模式 |
| 日志数据过时 | 日志轮转 | 每天会创建新的YYYYMMDD.log文件 |
| 路径包含空格 | 路径变量未加引号 | 为路径添加引号:"$LOG_FILE" |
| 敏感数据暴露 | 日志中包含交易信息 | 向用户报告时过滤敏感字段 |