Question

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

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

Was it helpful?

Solution

Paramiko doesn't output anything by default. You probably have a call to the logging module, setting a loglevel that's inherited when paramiko sets up it's own logging.

If you want to get at the paramiko logger to override the settings:

logger = paramiko.util.logging.getLogger()

There's also a convenience function to log everything to a file:

paramiko.util.log_to_file('filename.log')

OTHER TIPS

I don't know what Paramiko is, and there must be a log level setting for sure, but if you are desperate and looking for a temporary solution and if your app is single threaded

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

you can use StringIO for output also, if you are on an OS not have a '/dev/null'

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top