-
Notifications
You must be signed in to change notification settings - Fork 434
fix(logger): remove subclassing and move unnecessary APIs #2334
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Merged
leandrodamascena
merged 8 commits into
aws-powertools:develop
from
heitorlessa:fix/logger-subclassing
Jun 1, 2023
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6f82ea9
refactor: remove logging.Logger subclassing
heitorlessa d387260
refactor: move 3.8+ compat code to compat.py
heitorlessa 01ccb98
chore: improve docstring to mention the first handler/formatter only
heitorlessa 1fdfa22
Merge branch 'develop' into fix/logger-applications
heitorlessa facf6fc
refactor: proxy log_level to _logger.level
heitorlessa 04a736f
chore: address mypy for copy_config_to_registered_loggers
heitorlessa 6bc8a97
chore: move properties together
heitorlessa 70ba63e
Merge branch 'develop' into fix/logger-subclassing
leandrodamascena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Maintenance: We can drop this upon Py3.7 EOL. It's a backport for "location" key to work.""" | ||
from __future__ import annotations | ||
|
||
import io | ||
import logging | ||
import os | ||
import traceback | ||
|
||
|
||
def findCaller(stack_info=False, stacklevel=2): # pragma: no cover | ||
""" | ||
Find the stack frame of the caller so that we can note the source | ||
file name, line number and function name. | ||
""" | ||
f = logging.currentframe() # noqa: VNE001 | ||
# On some versions of IronPython, currentframe() returns None if | ||
# IronPython isn't run with -X:Frames. | ||
if f is None: | ||
return "(unknown file)", 0, "(unknown function)", None | ||
while stacklevel > 0: | ||
next_f = f.f_back | ||
if next_f is None: | ||
## We've got options here. | ||
## If we want to use the last (deepest) frame: | ||
break | ||
## If we want to mimic the warnings module: | ||
# return ("sys", 1, "(unknown function)", None) # noqa: E800 | ||
## If we want to be pedantic: # noqa: E800 | ||
# raise ValueError("call stack is not deep enough") # noqa: E800 | ||
f = next_f # noqa: VNE001 | ||
if not _is_internal_frame(f): | ||
stacklevel -= 1 | ||
co = f.f_code | ||
sinfo = None | ||
if stack_info: | ||
with io.StringIO() as sio: | ||
sio.write("Stack (most recent call last):\n") | ||
traceback.print_stack(f, file=sio) | ||
sinfo = sio.getvalue() | ||
if sinfo[-1] == "\n": | ||
sinfo = sinfo[:-1] | ||
return co.co_filename, f.f_lineno, co.co_name, sinfo | ||
|
||
|
||
# The following is based on warnings._is_internal_frame. It makes sure that | ||
# frames of the import mechanism are skipped when logging at module level and | ||
# using a stacklevel value greater than one. | ||
def _is_internal_frame(frame): # pragma: no cover | ||
"""Signal whether the frame is a CPython or logging module internal.""" | ||
filename = os.path.normcase(frame.f_code.co_filename) | ||
return filename == logging._srcfile or ("importlib" in filename and "_bootstrap" in filename) |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.