akarneliuk / pygnmi

The pure Python implementation of the gNMI client.
https://training.karneliuk.com
BSD 3-Clause "New" or "Revised" License
126 stars 44 forks source link

Logs to console #120

Open cliff-ha opened 1 year ago

cliff-ha commented 1 year ago

Will it be possible in the client to add support for having a choice if you want the client to print error messages to sys.stdout?

It could be added as an option where you setup the client to specify where to send the logging information.

In the beginning it could be a start just to have a bool to state wether or not to log to sys.stdout?

sebageek commented 1 year ago

pygnmi is consistently using the python logging framework (the only exception being some print()s when you add debug=True to some calls I hink). What I do in my code to get rid of the log message is to raise the log level to CRITICAL. You could also set it to higher than that to avoid any messages.

from pygnmi.client import gNMIclient
from pygnmi.client import logger as gnmi_logger

gnmi_logger.setLevel(logging.CRITICAL + 1)
client = gNMIclient(target=..., ...)
client.connect()

I'm not against adding a feature switch for this (and would have gladly used this myself if I'd seen it available), but this might help with your immediate problem.