Capture warnings.warn and friends messages in logs (#85875)
The default behavior of these warnings is to go to stderr, which in some setups goes easily unnoticed. For example in Docker based ones, they end up only in the container logs, and not e.g. in the HA log. Capture these to make them available in logs where other such messages are, and to make them subject to filtering as usual. https://docs.python.org/3/library/logging.html#logging.captureWarnings
This commit is contained in:
parent
3abcffe3a0
commit
cb22154b36
1 changed files with 5 additions and 0 deletions
|
@ -380,6 +380,11 @@ def async_enable_logging(
|
|||
# formatting. If the above succeeds, this will result in a no-op.
|
||||
logging.basicConfig(format=fmt, datefmt=datefmt, level=logging.INFO)
|
||||
|
||||
# Capture warnings.warn(...) and friends messages in logs.
|
||||
# The standard destination for them is stderr, which may end up unnoticed.
|
||||
# This way they're where other messages are, and can be filtered as usual.
|
||||
logging.captureWarnings(True)
|
||||
|
||||
# Suppress overly verbose logs from libraries that aren't helpful
|
||||
logging.getLogger("requests").setLevel(logging.WARNING)
|
||||
logging.getLogger("urllib3").setLevel(logging.WARNING)
|
||||
|
|
Loading…
Add table
Reference in a new issue