Skip to content

Scope logToFile and logToConsole handlers to ib_async logger#218

Open
mahimn01 wants to merge 1 commit into
ib-api-reloaded:nextfrom
mahimn01:scope-log-handlers
Open

Scope logToFile and logToConsole handlers to ib_async logger#218
mahimn01 wants to merge 1 commit into
ib-api-reloaded:nextfrom
mahimn01:scope-log-handlers

Conversation

@mahimn01
Copy link
Copy Markdown

Fixes #24.

Both logToFile and logToConsole were attaching their handlers to the root logger via logging.getLogger(), so calling them captured every log record in the process, not just records from ib_async.

Attaches handlers to logging.getLogger("ib_async") instead, and tightens the duplicate-detection check in logToConsole to inspect the ib_async namespace's own handlers plus root's (since records propagate up).

All internal modules already log under the ib_async.* namespace (decoder, wrapper, ib, client, ibcontroller, flexreport) and none disable propagation, so user setups that catch records on the root logger keep working.

The v0.9.67 fix referenced in docs/changelog.rst:437 (ib_insync #361) addressed the level-pollution side of this but left the handler attachment on root.

Includes tests/test_log_scoping.py covering: logToFile scope + third-party isolation, logToConsole scope, duplicate-handler detection on repeat call, and cross-namespace duplicate detection when root already has a stderr handler.

Both helpers were attaching their handlers to the root logger via
`logging.getLogger()`, so calling them captured every log record in the
process, not just records from ib_async.

Attach handlers to `logging.getLogger("ib_async")` instead, and tighten
the duplicate-detection check in `logToConsole` to inspect the ib_async
namespace's own handlers plus root's (since records propagate up).

The v0.9.67 fix referenced in `docs/changelog.rst:437` addressed the
level-pollution side of this but left the handler attachment on root.

Fixes ib-api-reloaded#24
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.

1 participant