ib_insync reduce logging verbosity

369 Views Asked by At

So, im trying to reduce the amount of debbug logging because its really bothering me. Im working with ib_insync, but im actually a tester, im pretty new to python. So, ive entered the util file, and change the logToConsole function but it didnt work. This how it looks like now:

` def logToConsole(level=logging.ERROR):

"""Create a log handler that logs to the console."""
logger = logging.getLogger()
stdHandlers = [
    h for h in logger.handlers
    if type(h) is logging.StreamHandler and h.stream is sys.stderr]
if stdHandlers:
    # if a standard stream handler already exists, use it and
    # set the log level for the ib_insync namespace only
    logging.getLogger('ib_insync').setLevel(level)
else:
    # else create a new handler
    logger.setLevel(level)
    formatter = logging.Formatter(
        '%(asctime)s %(name)s %(levelname)s %(message)s')
    handler = logging.StreamHandler()
    handler.setFormatter(formatter)
    logger.addHandler(handler)`

and this are the kind of messages im trying to avoid (i dont even know where they come from)

DEBUG: <<< 6,2,StockMarketValue,0.00,EUR,DU5856680 
1

There are 1 best solutions below

0
On

You can call ib_enable_log(logging.ERROR) to only log errors, or replace logging.ERROR with any other logging level you need, such as logging.WARNING or logging.CRITICAL

from ib_insync import util
import logging

def ib_enable_log(level=logging.ERROR):
    """Enables ib insync logging"""
    util.logToConsole(level)