Warnings logging doesn't log warnings
See original GitHub issueDescription
The Astropy logging mechanism provides the enable_warnings_logging()
function, which is claimed to enable logging of warnings.warn()
messages. This does not appear to work.
Expected behavior
Warnings signaled by warnings.warn
should be recorded in the log.
Actual behavior
Such warnings do not appear.
Steps to Reproduce
import warnings
from astropy import log
import astropy.logger
import logging
try:
log.enable_warnings_logging()
except astropy.logger.LoggingError:
pass
with log.log_to_file("test.log"):
log.warning("logger warning")
warnings.warn("warnings warning")
The file test.log
should contain both “logger warning” and “warnings warning” but it only contains “logger warning”.
(The exception handling is because the only way to ensure the astropy warnings logging mechanism is turned on is to call the function and catch the exception if it’s already turned on; it is in my completely default setup.)
System Details
>>> import platform; print(platform.platform())
Linux-3.10.0-862.14.4.el7.x86_64-x86_64-with-debian-buster-sid
>>> import sys; print("Python", sys.version)
Python 3.7.6 | packaged by conda-forge | (default, Jun 1 2020, 18:57:50)
[GCC 7.5.0]
>>> import numpy; print("Numpy", numpy.__version__)
Numpy 1.18.5
>>> import astropy; print("astropy", astropy.__version__)
astropy 4.0
>>> import scipy; print("Scipy", scipy.__version__)
Scipy 1.4.1
>>> import matplotlib; print("Matplotlib", matplotlib.__version__)
Matplotlib 3.0.3
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
python - captureWarnings set to True doesn't capture warnings
Warnings issued by the warnings module will be redirected to the logging system. Specifically, a warning will be formatted using warnings.formatwarning() and ...
Read more >How best to warn in Python: logs or `warnings`?
The question has come up on a code review whether we should use the warnings module or logging to warn in code that...
Read more >Some easy and pythonic way to bind warnings to loggers?
My proposal is that Python adds a supported simple way to wire a logger and a warning class: from logging import getLogger logger...
Read more >Integrating Python's logging and warnings packages - Medium
Failing to add logging.basicConfig line (or programmatic configuration) will lead that any logging messages from the code that runs before you ...
Read more >How to Get Started with Logging in Python - Better Stack
Notice that "Logging WARNING" was printed to the console, but "Logging INFO" wasn't. This is due to the default log levels configured on...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@aarchiba , #11562 is merged to clarify the logger usage. Can we close this? Thanks for bringing this to our attention!
Ops… Bot comment is accurate but I used the wrong API key. 😅