Skip to content

Fix/quiet the SDK's default logging output#29

Open
MarketDataDev03 wants to merge 1 commit into
mainfrom
logger_too_verbose
Open

Fix/quiet the SDK's default logging output#29
MarketDataDev03 wants to merge 1 commit into
mainfrom
logger_too_verbose

Conversation

@MarketDataDev03
Copy link
Copy Markdown
Collaborator

Fix: quiet the SDK's default logging output

Closes #25

Summary

Importing the SDK and constructing a MarketDataClient produced several INFO
log 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_LEVEL environment
variable.

This PR raises the SDK's default logging threshold to WARNING and downgrades
the chatty initialization messages to DEBUG. Users who want the previous
verbose behavior can still opt in via MARKETDATA_LOGGING_LEVEL=INFO.

Problem

from marketdata import MarketDataClient
c = MarketDataClient(token="...")
# 2026-05-28 ... INFO - Initializing MarketDataClient
# 2026-05-28 ... INFO - Base URL: https://api.marketdata.app
# 2026-05-28 ... INFO - API Version: v1
# 2026-05-28 ... INFO - GET 200 ... /user/

Three INFO entries just to instantiate the client, plus one per HTTP request.

Changes

src/marketdata/settings.py

-    marketdata_logging_level: str = "INFO"
+    marketdata_logging_level: str = "WARNING"

The default is now quiet. Library output stays out of the user's way unless
they opt in.

src/marketdata/client.py

         self.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 URL and API Version are implementation details, not user-facing
events. They are now at DEBUG, aligned with the existing Token log right
above them. They remain available for troubleshooting via
MARKETDATA_LOGGING_LEVEL=DEBUG.

What was intentionally left alone

  • Initializing MarketDataClient stays at INFO. The issue does not ask
    for it to move; a regression test pins this. With the new WARNING default,
    it is silent for normal users anyway.
  • Per-request log in _post_request_logs (response_log_level=INFO) is
    unchanged. 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 fresh
    MarketDataSettings() with MARKETDATA_LOGGING_LEVEL removed from the
    environment and asserts the default is "WARNING". Uses monkeypatch.delenv
    to neutralize any shell-leaked env var.
  • test_client_init_base_url_and_api_version_logged_at_debug — injects a
    MagicMock(spec=Logger) into the constructor and asserts:
    • Base URL / API Version are not in logger.info calls,
    • they are in logger.debug calls,
    • Initializing stays in logger.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
caplog setup.

Developed with a TDD red → green cycle.

297 passed

Full suite green — no regressions.

Files changed

File Change
src/marketdata/settings.py Default marketdata_logging_level: INFOWARNING
src/marketdata/client.py Base URL / API Version init logs: infodebug
src/tests/test_client.py 2 new regression tests

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (fb1ea8e) to head (30ac233).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #29   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           52        52           
  Lines         2281      2281           
=========================================
  Hits          2281      2281           
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MarketDataDev03 MarketDataDev03 marked this pull request as ready for review May 28, 2026 11:37
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

Successfully merging this pull request may close these issues.

Default logging level INFO is too verbose and hard to change

1 participant