Suppresses Paramico SSHClient class output

When I call the connection function of the Paramiko SSHClient class, it outputs some log data about the connection establishment that I would like to suppress.

Is there a way to do this, either through Paramiko itself, or Python in general?

+4
source share
2 answers

Paramiko does not display anything by default. You probably have a call to the logging module by installing loglevel, which is inherited when paramiko installs its own log.

If you want to get a paramiko registrar to override settings:

 logger = paramiko.util.logging.getLogger() 

There is also a convenience function for recording the entire file:

 paramiko.util.log_to_file('filename.log') 
+7
source

I don’t know what Paramiko is, and there must be a log level level, but if you are desperately looking for a workaround, and if your application is single-threaded

 import sys dev_null = sys.stdout = sys.stderr = open('/dev/null', 'w') try: . . connect() . finally: dev_null.close() 

you can also use StringIO for output if you don't have the OS / dev / null '

0
source

All Articles