fix(logging): harness WARNING+ 日志镜像到 stderr,journalctl 可见 - #603
Open
angri450 wants to merge 1 commit into
Open
Conversation
_setup_logging only attached the rotating-file handler to the root and uvicorn loggers, so harness diagnostics (model failover, tool guard, ...) landed in ~/.octop/logs/*.log but never reached stderr — invisible to journalctl -u octop during incident triage. Attach an idempotent stderr StreamHandler (WARNING+) to the harness_agent logger; file keeps receiving full logs, stderr mirrors warnings and above, same dual-path as the uvicorn loggers.
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.
问题
服务端排查模型切换问题时发现:harness 层的诊断日志(如模型路由 failover 的
model failover: ... failed (...), trying next)在journalctl -u octop里完全看不到。根因:
_setup_logging只给 root logger 和 uvicorn 系列 logger 挂了滚动文件 handler,所有日志(含 WARNING+)只落~/.octop/logs/*.log,进程 stderr 无输出;journald 捕获不到。排障时终端侧是盲的。修复
_attach_harness_stderr_handler():给harness_agentlogger 附加 stderr StreamHandler(WARNING 及以上,带%(levelname)s:%(name)s格式),覆盖 model failover、tool guard 等全部 harness 诊断日志_octop_harness_stderrmarker 属性,重复 setup 不叠加_setup_logging末尾调用测试
tests/unit/infra/test_server_logging.py:2 个用例(handler 只挂一次 + level=WARNING;warning 记录确实带 logger 名输出到 stderr),本地 pytest 通过journalctl -u octop实时出现WARNING:harness_agent.middleware.model_failover: model failover: ... (OpenAIAuthenticationError: 401 ...), trying next背景
模型路由 failover(按用户配置的链依次切换模型)目前运行在 harness_agent 层,日志经此修复可在服务端直接观测切换行为。