Fix/quiet the SDK's default logging output#29
Open
MarketDataDev03 wants to merge 1 commit into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #29 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 52 52
Lines 2281 2281
=========================================
Hits 2281 2281
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Fix: quiet the SDK's default logging output
Closes #25
Summary
Importing the SDK and constructing a
MarketDataClientproduced several INFOlog lines — and one more on every HTTP request — flooding the user's terminal
with output most callers do not care about. Worse, the only way to silence it
was to discover the undocumented
MARKETDATA_LOGGING_LEVELenvironmentvariable.
This PR raises the SDK's default logging threshold to
WARNINGand downgradesthe chatty initialization messages to
DEBUG. Users who want the previousverbose behavior can still opt in via
MARKETDATA_LOGGING_LEVEL=INFO.Problem
Three INFO entries just to instantiate the client, plus one per HTTP request.
Changes
src/marketdata/settings.pyThe default is now quiet. Library output stays out of the user's way unless
they opt in.
src/marketdata/client.pyself.logger.debug(f"Token: {logged_token}") - self.logger.info(f"Base URL: {settings.marketdata_base_url}") - self.logger.info(f"API Version: {settings.marketdata_api_version}") + self.logger.debug(f"Base URL: {settings.marketdata_base_url}") + self.logger.debug(f"API Version: {settings.marketdata_api_version}")Base URLandAPI Versionare implementation details, not user-facingevents. They are now at
DEBUG, aligned with the existingTokenlog rightabove them. They remain available for troubleshooting via
MARKETDATA_LOGGING_LEVEL=DEBUG.What was intentionally left alone
Initializing MarketDataClientstays atINFO. The issue does not askfor it to move; a regression test pins this. With the new
WARNINGdefault,it is silent for normal users anyway.
_post_request_logs(response_log_level=INFO) isunchanged. Not part of the proposed solution, and the new default silences
it for casual use while still surfacing it when users explicitly raise the
level.
Testing
Two new tests in
src/tests/test_client.py, one per change:test_default_logging_level_is_warning— instantiates a freshMarketDataSettings()withMARKETDATA_LOGGING_LEVELremoved from theenvironment and asserts the default is
"WARNING". Usesmonkeypatch.delenvto neutralize any shell-leaked env var.
test_client_init_base_url_and_api_version_logged_at_debug— injects aMagicMock(spec=Logger)into the constructor and asserts:Base URL/API Versionare not inlogger.infocalls,logger.debugcalls,Initializingstays inlogger.info(sanity check that locks behavior).Mocking the logger directly lets the tests verify which method was called
without depending on log-level filtering, root-logger propagation, or
caplogsetup.Developed with a TDD red → green cycle.
Full suite green — no regressions.
Files changed
src/marketdata/settings.pymarketdata_logging_level:INFO→WARNINGsrc/marketdata/client.pyBase URL/API Versioninit logs:info→debugsrc/tests/test_client.py