-
-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added CallsiteNamespaceAdder
processor
#570
Conversation
for more information, see https://pre-commit.ci
As mentioned in the original PR #568 , the use of Sample code:
|
@hynek Thoughts? |
AddCallingNamespace
processorCallsiteNamespaceAdder
processor
src/structlog/processors.py
Outdated
def __call__( | ||
self, logger: WrappedLogger, name: str, event_dict: EventDict | ||
) -> EventDict: | ||
if self.levels and name not in self.levels: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using levels as a container doesn't make a lot of sense given how it's used elsewhere. Unless you have a good reason for it, I think it should be an int that is compared against.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to int
src/structlog/processors.py
Outdated
f"{member.__module__}.{member.__qualname__}" | ||
) | ||
# we found our code match, can stop looking | ||
namespace_found = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A simple break
should do, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had that, but it was failing coverage tests due to the early exit to the loop. Re-wrote it this way to hit the 100% mark.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reverted back to break
based logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name Stmts Miss Branch BrPart Cover Missing
----------------------------------------------------------------------
src/structlog/_frames.py 47 0 15 1 98% 104->115
----------------------------------------------------------------------
TOTAL 1781 0 462 1 99%
18 files skipped due to complete coverage.
Coverage failure: total of 99 is less than fail-under=100
Error: Process completed with exit code 2.
There is the coverage fault on the break
logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got creative and worked around it without needing to nocover
it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What this is telling you means that you're missing branch coverage. I suspect it means that the loop never loops twice (aka: the break is always executed)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct — which is why the “should operate at O(1)” comment… loop is to be thorough for edge cases.
I got it cleaned and passing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so this is actually great, because I honestly don't quite understand what/how the code is doing.
Could you please in plain words explain to me what it's doing? Finding a test case where it needs more than one iteration is very helpful for my understanding.
Co-authored-by: Hynek Schlawack <[email protected]>
Co-authored-by: Hynek Schlawack <[email protected]>
Co-authored-by: Hynek Schlawack <[email protected]>
Co-authored-by: Hynek Schlawack <[email protected]>
Co-authored-by: Hynek Schlawack <[email protected]>
Co-authored-by: Hynek Schlawack <[email protected]>
Co-authored-by: Hynek Schlawack <[email protected]>
Co-authored-by: Hynek Schlawack <[email protected]>
Co-authored-by: Hynek Schlawack <[email protected]>
Co-authored-by: Hynek Schlawack <[email protected]>
Co-authored-by: Hynek Schlawack <[email protected]>
src/structlog/_frames.py
Outdated
identified_namespace = f"{cls.__module__}.{frame.f_code.co_name}" | ||
if inspect.isfunction(member) and member.__code__ == frame.f_code: | ||
# we found our code match, can stop looking | ||
"""identified_namespace = f"{member.__module__}.{member.__qualname__}" """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this?
No rush, but I'm probably gonna push a PyPI release soon-ish, but if you'd like this to be part of it, we should try to wrap things up here. |
Summary
Added a
namespace
event entry processor asAddCallingNamespace
-- replacing #568 with a recommendation from @macintacos to change the references fromclass_path
tonamespace
Referenced in #386
Referenced in #492
Takes an optional
set
orlist
to limit which logging levels to add this at, as lookups potentially can add overhead (though should run in N(1)).Pull Request Check List
main
branch – use a separate branch!api.py
.docs/api.rst
by hand.versionadded
,versionchanged
, ordeprecated
directives..rst
and.md
files is written using semantic newlines.