Fix #70: stop calling logging.basicConfig() at import time#71
Merged
Conversation
gtfparse called logging.basicConfig(level=logging.INFO) at module import in three modules (read_gtf, attribute_parsing, create_missing_features). As a library this is an anti-pattern: it configures the root logger on behalf of the importing application, adding a handler and forcing the INFO level onto everyone's root logger — hijacking the host app's logging. Remove the basicConfig() calls and route the remaining log statements through the module-level `logger` (logging.getLogger(__name__)) instead of the root-logger convenience functions logging.info(...), which would otherwise implicitly re-trigger basicConfig(). Configuring handlers/levels is now left entirely to the application, per the standard library logging guidance for libraries. Claude-Session: https://claude.ai/code/session_014fNxSBm5zvdsDNwN3nhmpS
Coverage Report for CI Build 28968279719Coverage decreased (-0.07%) to 95.146%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions8 previously-covered lines in 3 files lost coverage.
Coverage Stats
💛 - Coveralls |
Closed
Pass log message arguments to logger.info(...) rather than pre-formatting with the % operator, so the interpolation is skipped entirely when the log level is disabled (the standard logging idiom, per pylint's logging-not-lazy guidance). Claude-Session: https://claude.ai/code/session_014fNxSBm5zvdsDNwN3nhmpS
Patch release: gtfparse no longer calls logging.basicConfig() at import time, so importing the library no longer reconfigures the host application's root logger (#70). Claude-Session: https://claude.ai/code/session_014fNxSBm5zvdsDNwN3nhmpS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #70. gtfparse called
logging.basicConfig(level=logging.INFO)at module import time in three modules:gtfparse/read_gtf.pygtfparse/attribute_parsing.pygtfparse/create_missing_features.pyFor a library this is a well-known anti-pattern.
basicConfig()configures the root logger on behalf of whatever application imports us — it attaches aStreamHandlerand forces the level toINFO. Simplyimport gtfparsetherefore hijacks the host application's logging setup (its handlers/level get overridden by whichever module happens to import first).Fix
logging.basicConfig(level=logging.INFO)calls.logger(logging.getLogger(__name__)) instead of the root-logger convenience functions (logging.info(...)), which would otherwise implicitly re-triggerbasicConfig()on first use.Configuring handlers and levels is now left entirely to the application, per the stdlib logging guidance for libraries. The library only emits records through its named loggers.
Verification
import gtfparseno longer adds handlers to or changes the level of the root logger, and the package's named loggers stay atNOTSET.caplog-based log-capture tests intests/test_gencode_gtf.py.ruff checkandruff format --checkclean.https://claude.ai/code/session_014fNxSBm5zvdsDNwN3nhmpS