Skip to content

fix: silence default stderr logging via NullHandler (closes #36) - #79

Open
Nexory wants to merge 1 commit into
Polymarket:mainfrom
Nexory:fix/silence-default-stderr-logging
Open

fix: silence default stderr logging via NullHandler (closes #36)#79
Nexory wants to merge 1 commit into
Polymarket:mainfrom
Nexory:fix/silence-default-stderr-logging

Conversation

@Nexory

@Nexory Nexory commented May 25, 2026

Copy link
Copy Markdown

Summary

Adds a NullHandler to the package's top-level logger so py_clob_client_v2 does not emit log records via Python's lastResort handler when the consuming application has not configured logging.

This is the standard library-logging pattern recommended in the Python logging cookbook:

"If a library user does not configure logging, and library code makes logging calls, then ... a one-off message 'No handlers could be found for logger X.Y.Z' is printed to the console."

Without this change, modules that log at ERROR (e.g. http_helpers/helpers.py:73 and :89, both prefixed [py_clob_client_v2]) print to stderr by default, which breaks curses-based terminal UIs and prevents callers from handling errors fully on their own.

Closes #36.

Change

import logging as _logging
_logging.getLogger(__name__).addHandler(_logging.NullHandler())

Added at the top of py_clob_client_v2/__init__.py before the public imports. The underscore on the import prevents from py_clob_client_v2 import * from re-exporting logging.

Behaviour

Caller's logging setup Before this PR After this PR
No logging configured SDK errors print to stderr via lastResort Silent
logging.basicConfig(...) configured SDK errors go to user's handlers (unchanged) SDK errors go to user's handlers (unchanged)
User opts in: logging.getLogger("py_clob_client_v2").setLevel(...) Works Works

Test plan

  • Manual check: import py_clob_client_v2 in a fresh interpreter with no logging config; confirm no warning is printed.
  • Manual check: configure root logger; confirm SDK errors still propagate to the configured handler.
  • CI passes.

Happy to add a regression test in tests/ if maintainers prefer.

Closes Polymarket#36

Adds a NullHandler to the package's top-level logger so the library does
not emit log records via Python's lastResort handler when the consuming
application has not configured logging.

This matches the standard library-logging pattern recommended in the
Python docs (https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library).

Users who want to see internal SDK logs can opt in:

    logging.getLogger("py_clob_client_v2").setLevel(logging.INFO)
    logging.getLogger("py_clob_client_v2").addHandler(handler)

Without this change, modules that log at ERROR (e.g. http_helpers.helpers)
print to stderr by default, which breaks curses-based terminal UIs and
prevents callers from handling errors entirely on their own.
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.

Bug: v2 unexpectedly prints() errors to console, breaking python curses layouts

1 participant