-
Notifications
You must be signed in to change notification settings - Fork 716
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
Capturing warnings with the correct source location #1076
Comments
You can certainly use the
If you can confirm that works, I will update the documentation. |
Yes, that did it, thanks for such a quick reply 😁 |
Great, you're welcome. 👍 |
Hi, sorry to bother you again. Have you ever passed the Unfortunately seems like |
Hum, that's a pitty... I don't think there's any clean way of doing it, unfortunately. Technically, you could iterate the stack to retrieve the depth where def showwarning(message, category, filename, lineno, file=None, line=None):
logger.opt(depth=2).warning("Warning emitted from '{}:{}': {}", message, filename, lineno)
showwarning_(message, category, filename, lineno, file, line) |
https://loguru.readthedocs.io/en/stable/resources/recipes.html#capturing-standard-stdout-stderr-and-warnings
When logging the path from which the warning message occurred, it will show the exact location of where you patched
showwarning
instead of where the warning message was actually called from.For example, the first and last warnings are coming from PyTorch Lightning, but here it says that they come from my
logging.py
module, where I did what's described in the link above.Is there any viable solution to this? Thanks!
The text was updated successfully, but these errors were encountered: