Mayil-AI / loguru

MIT License
0 stars 0 forks source link

Capturing warnings with the correct source location (hashtag1076) #6

Open vikramsubramanian opened 3 months ago

vikramsubramanian commented 3 months ago

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.

<img width="1100" alt="image" src="

Is there any viable solution to this? Thanks!

)

mayil-ai[bot] commented 3 months ago

Possible Solution

Code snippets to check

loguru → _logger.py This snippet includes the logic for capturing the file path and line number when logging, which is directly related to the issue of incorrect source location in warnings. https://github.com/Mayil-AI/loguru/blob/871de74acb2382fb3982d3fb8e224e4a82de9073/loguru/_logger.py#L1906-L2020 This snippet describes the logger configuration, which could be relevant when investigating how warnings are captured and logged. https://github.com/Mayil-AI/loguru/blob/871de74acb2382fb3982d3fb8e224e4a82de9073/loguru/_logger.py#L253-L2094
loguru → _better_exceptions.py This snippet is part of the exception formatting which might be involved in the process of logging warnings and their source locations. https://github.com/Mayil-AI/loguru/blob/871de74acb2382fb3982d3fb8e224e4a82de9073/loguru/_better_exceptions.py#L331-L380 This snippet deals with extracting frames and source information from tracebacks, which could be related to how the source location of warnings is determined. https://github.com/Mayil-AI/loguru/blob/871de74acb2382fb3982d3fb8e224e4a82de9073/loguru/_better_exceptions.py#L192-L254