Skip to content

fix: Improve redirected log level guess and drain async logs on stop - #1229

Merged
Pijukatel merged 4 commits into
apify:masterfrom
pcbeingused333:fix/c3526-streamed-log
Nov 19, 2026
Merged

Pijukatel merged 4 commits into
apify:masterfrom
pcbeingused333:fix/c3526-streamed-log

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

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.timeout raises TimeoutError; 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.

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.
@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Nov 15, 2026
@vdusek
vdusek requested a review from Pijukatel November 16, 2026 11:00
Comment thread src/apify_client/_streamed_log.py Resolved
Comment thread src/apify_client/_streamed_log.py Resolved
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.
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

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 wait_for. One addition: cancellation from the caller propagates through cancelling(), and a unit test covers it.

This comment was drafted with Claude Code.

@Pijukatel Pijukatel changed the title fix!: preserve streamed log severity and drain async logs on stop fix: Improve redirected log level guess and drain async logs on stop Nov 19, 2026
@Pijukatel

Pijukatel commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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 wait_for. One addition: cancellation from the caller propagates through cancelling(), and a unit test covers it.

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 _guess_log_level_from_message, I do not consider this a breaking change.

@Pijukatel
Pijukatel merged commit d10a7d6 into apify:master Nov 19, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streamed log redirection guesses levels from any substring and drops in-flight lines on async stop

2 participants