Repository navigation
fix(logger): preserve caller location, exc_info and creation timestam… - #8837
Conversation
…p in buffered log records
|
heyy @leandrodamascena pls review my PR and let me know if anythings needs to be added, changed or removed. |
leandrodamascena
left a comment
There was a problem hiding this comment.
Thanks @dropps07! This is the fix I hoped for: one code path, and a buffered record now prints exactly like the unbuffered one. I wrote a side-by-side probe for stacklevel, a saved exception, a third-party logger with stack_info and the timestamp, and with your branch the two outputs are identical on every field. Keeping only True as "resolve now" is the right reading of exc_info. Goes out in 3.42.0, no need to rebase, you'll be in the release notes.
perfect. sounds good :) |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #8837 +/- ##
===========================================
- Coverage 97.14% 97.08% -0.07%
===========================================
Files 327 327
Lines 16839 16865 +26
Branches 1540 1545 +5
===========================================
+ Hits 16359 16374 +15
- Misses 337 345 +8
- Partials 143 146 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
heyy @leandrodamascena do i have to resolve codecov issues ?? |
|
Hi @leandrodamascena, this PR is approved and ready on my side. Could you please merge it when you get a chance so it makes 3.42.0. Thanks. |
|
@dropps07 #8865 landed just ahead of you and it touches the same block in |
Signed-off-by: Ajey Awasthi <115537579+dropps07@users.noreply.github.com>
The web conflict resolution dropped the buffer config guard, mis-indented the six new keyword arguments, and nested the new test inside the previous one so the file did not compile. This restores the guard, fixes the indentation, and puts the new test back at module level. Test plan: pytest tests/unit/logger tests/functional/logger, 259 passed. Ruff format and check clean. Mypy clean on aws_lambda_powertools/logging.
|
hi @leandrodamascena, resolved the conflict the way you described. kept the new structure from develop, the record is built first and emitted straight away when there is no trace id, and added the six keyword arguments to the create buffer record call. kept both blocks in the test file, the new test from develop and my four. the branch is updated and the logger tests pass locally. your earlier approval got dismissed by the new pushes, could you take another look when you get a chance. thanks |
copy_config_to_registered_loggers without include= wired buffering into every registered logger, boto3 included, and thirteen DynamoDB provider tests running later failed with KeyError: 0 on flush.
|
@dropps07 one more thing I found while merging: the third-party test calls |
leandrodamascena
left a comment
There was a problem hiding this comment.
Approved again on f148912, same change plus the one-line test scope.
|
3ff475d
into
aws-powertools:develop
Resolves the overlap with aws-powertools#8837: the buffer record keeps the stacklevel-aware frame walk from develop, _log passes stacklevel through to the buffer, and both sets of buffer tests stay.



Issue number: closes #8824
Summary
Changes
Buffered log records now print exactly as they would have been without buffering. Three fixes in the same code path:
User experience
Before: a buffered debug log from a wrapper with stacklevel=3 reported the wrapper instead of the business function, a third-party log showed location handle:1028 with the Powertools logger name, an exception logged outside its except block flushed with no exception, and every flushed record printed the flush time. After: each flushed record is identical to the same log without buffering, same location, name, stack info, exception and timestamp.
Verification
I ran the tests myself and pasted what I saw, I did not describe runs I did not do.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.