Skip to content
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

[DRAFT] Add CallsiteInfoAdder class which populates the event dictionary with callsite info #380

Closed
wants to merge 12 commits into from

Conversation

aucampia
Copy link
Contributor

@aucampia aucampia commented Dec 7, 2021

Summary

This PR creates a CallsiteInfoAdder processor which will populate the event dictionary with callsite info:

Attribute name Description
pathname Full pathname of the source file where the logging call was issued (if available).
filename Filename portion of pathname.
module Module (name portion of filename).
funcName Name of function containing the logging call.
lineno Source line number where the logging call was issued (if available).
thread Thread ID (if available).
threadName Thread name (if available).
process Process ID (if available).
processName Process name (if available).

Fixes #378

Pull Request Check List

This is just a friendly reminder about the most common mistakes. Please make sure that you tick all boxes. But please read our contribution guide at least once, it will save you unnecessary review cycles!

If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing left to do.

  • Added tests for changed code.
  • New APIs are added to typing_examples.py.
  • Updated documentation for changed code.
    • New functions/classes have to be added to docs/api.rst by hand.
    • Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives. Find the appropriate next version in our __init__.py file.
  • Documentation in .rst files is written using semantic newlines.
  • Changes (and possible deprecations) are documented in the changelog.

If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!

@hynek
Copy link
Owner

hynek commented Dec 8, 2021

I like the approach and I have only two concerns:

  1. The thread info is probably gonna be wrong in async setups. We can say that's fine, but then we'd have to document it.
  2. Similar problem: we probably should allow the user to supply more names for additional_ignores?

@aucampia
Copy link
Contributor Author

aucampia commented Dec 8, 2021

I like the approach and I have only two concerns:

  1. The thread info is probably gonna be wrong in async setups. We can say that's fine, but then we'd have to document it.
  2. Similar problem: we probably should allow the user to supply more names for additional_ignores?

Thanks for the heads up on these, I will do some testing with async to see what is what, and I will allow user control of additional_ignores and I think the default in this case is redundant.

@aucampia aucampia force-pushed the iwana-20211207T2210-callsite_info branch from 200a064 to 90d55d2 Compare December 11, 2021 15:41
@aucampia aucampia force-pushed the iwana-20211207T2210-callsite_info branch from d4df105 to 351b1ac Compare December 12, 2021 18:21
@aucampia
Copy link
Contributor Author

deleting this PR as I will create a new one from same branch to work around the branch editing issue.

@aucampia aucampia closed this Dec 12, 2021
@gzmarstone
Copy link

gzmarstone commented Dec 16, 2021

I know its closed, but what about class if available as well... use case would be to find all of the logging calls in a particular class... You can check if the first arg is self, if it is then get the class and the name of that?
I used this example to log the classname via structlog: https://stackoverflow.com/questions/2203424/python-how-to-retrieve-class-information-from-a-frame-object

@aucampia
Copy link
Contributor Author

aucampia commented Dec 16, 2021

I used this example to log the classname via structlog: https://stackoverflow.com/questions/2203424/python-how-to-retrieve-class-information-from-a-frame-object

@gzmarstone Nice to know about this, I will consider adding this - would be nice to have - but will only get time to look at it next year if at all. The main goal was to get parity with capabilities of the stdlib logger regarding callsite info.

Update:

You could create a logger on a class, named for the class and the module, and then use the logger name.

@gzmarstone
Copy link

No problem, I just noticed the change with the latest release and it would let me delete the code that I had to implemented to log the stdlib items, but then realized that it was missing the Class which I have, so I couldn't delete all of it yet... I can just leave that part in my code and if it gets added obsolete it, otherwise no big deal...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add callsite info to event dictionary
3 participants