Skip to content
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

Capture warnings.warn and friends messages in logs #85875

Merged
merged 1 commit into from May 18, 2023

Conversation

scop
Copy link
Member

@scop scop commented Jan 14, 2023

Proposed change

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

Note:

Doing this might end up us seeing more warnings in logs than before. Should keep an eye on if something additional needs to be filtered out by default. These entries are identifiable and filterable by the logger name py.warnings, warning level.

One such suspect is urllib3's unverified HTTPS request warning, https://github.com/urllib3/urllib3/blob/b1d5b2260949f346e0fe13b7495e71c84abff07f/src/urllib3/connectionpool.py#L1097-L1105, which is triggered by requests requests with verify=False, which is something a number of underlying deps of integrations do.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@scop scop requested a review from a team as a code owner January 14, 2023 15:15
@home-assistant home-assistant bot added cla-signed core new-feature small-pr PRs with less than 30 lines. labels Jan 14, 2023
@scop
Copy link
Member Author

scop commented Jan 14, 2023

The mentioned urllib3 warning might be good to leave for users or integrations to filter out instead of blanket filtering it at top level; it's security related anyway. On the other hand it's also chatty as it is emitted for every affected request.

@github-actions
Copy link

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@github-actions github-actions bot added the stale label Apr 14, 2023
@github-actions github-actions bot closed this Apr 21, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Apr 22, 2023
@scop scop reopened this Apr 26, 2023
@scop scop force-pushed the scop-logging-capturewarnings branch from 5fd0650 to 2de7ac9 Compare April 26, 2023 14:50
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
@scop scop force-pushed the scop-logging-capturewarnings branch from 2de7ac9 to 69ce09e Compare May 18, 2023 13:07
@home-assistant home-assistant unlocked this conversation May 18, 2023
Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been running this for a month on my production and didn't notice any issues 👍

@github-actions github-actions bot removed the stale label May 18, 2023
@scop scop merged commit cb22154 into dev May 18, 2023
52 checks passed
@scop scop deleted the scop-logging-capturewarnings branch May 18, 2023 18:41
@github-actions github-actions bot locked and limited conversation to collaborators May 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants