fix: WtBtAnalyst使用print直写控制台,宿主无法按需接管输出 - #192
Open
xukanshan wants to merge 1 commit into
Open
Conversation
问题背景: wtpy Python层已有两类受控输出通道: 引擎生命周期消息经api.write_log进入C++ WTSLogger, 由logcfg统一管理; datahelper子模块使用标准logging。但 apps/WtBtAnalyst.py的分析进度信息使用裸print直写stdout, 未走任何可配置通道。 问题表现: 宿主调用WtBtAnalyst.run_new()/run()/run_simple()时, 控制台被强制打印 "start PnL analyzing..."等进度文本。print绕开logging体系: 宿主既无法静音, 也无法重定向到日志文件; 在宿主使用控制台单行刷新(\r)展示自定义进度的场景下, 输出还会被打断错位。 问题原因: run_new()/run()/run_simple()与funds_analyze()中共6处进度输出以print()直写, 与同目录datahelper子模块的logging用法不一致。 问题修复: 模块级新增_logger = logging.getLogger(__name__), 6处print改为_logger.info。 logging在宿主未配置handler时INFO级别默认不输出, 库默认行为变为安静; 宿主 可按需通过logging配置接管输出的去向与级别。消息文本与执行逻辑不变, 仅变更 输出通道。 验证: python -m py_compile通过; 以实际运行的量化选股策略端到端回测验证, 绩效分析 产物(xlsx/summary.json)与修复前一致, 控制台不再出现强制输出。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题背景:
wtpy Python层已有两类受控输出通道: 引擎生命周期消息经api.write_log进入C++ WTSLogger, 由logcfg统一管理; datahelper子模块使用标准logging。但 apps/WtBtAnalyst.py的分析进度信息使用裸print直写stdout, 未走任何可配置通道。
问题表现:
宿主调用WtBtAnalyst.run_new()/run()/run_simple()时, 控制台被强制打印 "start PnL analyzing..."等进度文本。print绕开logging体系: 宿主既无法静音, 也无法重定向到日志文件; 在宿主使用控制台单行刷新(\r)展示自定义进度的场景下,
输出还会被打断错位。
问题原因:
run_new()/run()/run_simple()与funds_analyze()中共6处进度输出以print()直写, 与同目录datahelper子模块的logging用法不一致。
问题修复:
模块级新增_logger = logging.getLogger(name), 6处print改为_logger.info。 logging在宿主未配置handler时INFO级别默认不输出, 库默认行为变为安静; 宿主
可按需通过logging配置接管输出的去向与级别。消息文本与执行逻辑不变, 仅变更
输出通道。
验证:
python -m py_compile通过; 以实际运行的量化选股策略端到端回测验证, 绩效分析
产物(xlsx/summary.json)与修复前一致, 控制台不再出现强制输出。