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

Detect unused loggers #15

Open
adamchainz opened this issue Aug 24, 2023 · 0 comments
Open

Detect unused loggers #15

adamchainz opened this issue Aug 24, 2023 · 0 comments

Comments

@adamchainz
Copy link
Owner

adamchainz commented Aug 24, 2023

Description

Sometimes modules are copy-pasta'd to create new ones, leading to the getLogger() preamble being duplicated but not used:

import logging
logger = logging.getLogger(__name__)  # never used

These unused loggers don’t take long to construct, about 1µs, but they do live forever in the logging tree (seen with logging.Logger.manager.loggerDict), wasting memory and potentially hampering efforts to debug logging.

Let’s detect and flag module-level loggers that aren’t used anywhere in their file.

(I’ve found such cases before with this regular expression: (?s)^logger = (?!.*?logger.*$))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant