Repository navigation
fix: Improve redirected log level guess and drain async logs on stop - #1229
Conversation
Read the level token after the platform timestamp and optional logger prefix. Allow in-flight asynchronous log chunks to finish for one second before cancellation. BREAKING CHANGE: Redirected severity follows the level token rather than message substrings; async stop may wait up to one second before cancelling.
Use the first whole-word level name with ANSI colors removed, and wait for the streaming task with a plain wait_for, as suggested in review.
|
Thanks @Pijukatel. I pushed e71c4f6 with the review applied: the level guess now strips ANSI codes and only looks at the first level, and the async stop wait is simplified to a plain This comment was drafted with Claude Code. |
Thanks, looks good. I took the liberty of updating the PR title and and description. Since it is improving the function that clearly says it is just estimation |
Fixes #1180
Improved the redirected log level guess by deciding the log level by stripping color coding from log and selecting the first log level keyword that matches.
Give asynchronous log streaming a one-second grace period on stop so in-flight final chunks can arrive. Cancel streams that remain open after that period. Caller cancellation cancels and awaits the streaming task, clears its handle, and propagates without fetching the whole log. Normal stopping retains buffered-tail flushing and the whole-log fallback when no bytes arrived.
Testing and validation
Unit tests cover misleading message text, bracketed logger names, unknown or absent levels, delivery on the next event-loop turn, and cancellation of a silent stream. Explicit caller cancellation leaves the stopping task cancelled, and an enclosing
asyncio.timeoutraisesTimeoutError; neither path fetches the whole log. The focused suite passes all 16 tests (python -m pytest tests/unit/test_streamed_log.py -q). The two caller-cancellation regressions fail against the previous revision (14 passed, 2 failed). Ruff lint and format checks pass.AI assistance: This change and its tests were prepared with OpenAI Codex.