Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Fixed logToConsole chaning root logger configuration, now log level c… #361

Closed
wants to merge 1 commit into from

Conversation

beaverden
Copy link

In the context of this file, the last logging.debug message will not displayed, because logToConsole changes the root logger configuration. I spent an hour debugging bizare logger errors out of my multi-layered system

import ib_insync
import logging

logging.basicConfig(level=logging.DEBUG)

ib_insync.util.logToConsole(level=logging.ERROR)

ib = ib_insync.IB()
ib.connect('127.0.0.1', port=7497, clientId=1, readonly=True)
logging.debug('I will not be displayed')

So I added an optional boolean only_for_package to change only ib_insync.* loggers

import ib_insync
import logging

logging.basicConfig(level=logging.DEBUG)

ib_insync.util.logToConsole(level=logging.ERROR, only_for_package=True)

ib = ib_insync.IB()
ib.connect('127.0.0.1', port=7497, clientId=1, readonly=True)
logging.debug('I will be displayed')

As a side note, there seems to be some incompatibility of logToConsole (aka logging) and asyncio. https://stackoverflow.com/questions/64679139/nameerror-name-open-is-not-defined-when-trying-to-log-to-files

…an be manipulated at a package-level scope for all ib_insync.* loggers
@erdewit erdewit closed this in 7950f22 Oct 9, 2021
@erdewit
Copy link
Owner

erdewit commented Oct 9, 2021

This is now fixed in a bit different way that does not require the extra only_for_package argument.

flepied pushed a commit to flepied/ib_insync that referenced this pull request Apr 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants