Reputation: 1290
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?
Upvotes: 4
Views: 8285
Reputation: 11
You can do something like this:
paramiko_logger = logging.getLogger("paramiko")
paramikoHandler = logging.NullHandler() # no handler for summary messages
paramiko_logger.addHandler(paramikoHandler)
Basically, this accesses/creates the "paramiko" logger, and sets it to use a Null handler.
Paramiko is following bad form by logging errors to output/error regardless of whether they are caught or not.
Upvotes: 0
Reputation: 109325
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')
Upvotes: 7
Reputation: 2272
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'
Upvotes: 0