Evaluate every rotation condition so a skipped one cannot fire spuriously - #1515
Open
januththedev wants to merge 1 commit into
Open
januththedev wants to merge 1 commit into
januththedev wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Rotation: every condition is now evaluated, so a skipped one cannot fire spuriously
Description
A list of rotation conditions is combined with
any():any()over a generator short-circuits. That is fine for the return value, but eachRotationTimecondition is stateful: it lazily computesself._limiton first call and then advances it as a side effect of being invoked (loguru/_file_sink.py:154-157, thewhile self._limit <= record_time: self._step_forward(...)catch-up loop).When the first condition returns
True, the remaining conditions are never invoked, so their_limitis never advanced past the current time. A skipped condition is left holding a limit that is now in the past, and it therefore fires on the very next logged message — producing a second, immediate, spurious rotation.Reproduction
logger.add(path, rotation=["13:00", "12:00"]), file created at 06:00, process idle until 13:00:01, then two messages:Message
"b"legitimately rotates at 13:00:01;"c"should not. The"12:00"condition's stale2020-01-01 12:00limit is what caused the second rotation.The change
This keeps the documented "any of which can trigger the rotation" contract for the return value while restoring the side effect the conditions rely on.
Tests
test_multiple_rotation_conditions_all_evaluatedis added totests/test_filesink_rotation.py.assert 3 == 2; passes after.pytest tests/test_filesink_rotation.py→ 147 passed, 4 skipped (146 before).ruff checkclean.One note:
ruff format --checkreports one pre-existing trailing-comma difference at_file_sink.py:189(**kwargsvs**kwargs,) because my ruff differs from the pinned v0.15.7. I left it untouched.The list-of-conditions feature itself is unreleased (still in
Unreleasedfrom #1174), so the changelog entry is filed under that issue rather than needing a new one.