question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warnings logging doesn't log warnings

See original GitHub issue

Description

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:closed
  • Created 2 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
pllimcommented, Apr 28, 2021

@aarchiba , #11562 is merged to clarify the logger usage. Can we close this? Thanks for bringing this to our attention!

0reactions
pllimcommented, Aug 30, 2021

Ops… Bot comment is accurate but I used the wrong API key. 😅

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found