How to use Paramiko logging?
Paramiko names its loggers, so simply:
import logging
import paramiko
logging.basicConfig()
logging.getLogger("paramiko").setLevel(logging.WARNING) # for example
See the logging cookbook for some more examples.
You can also use log_to_file
from paramiko.util
to log directly to a file.
Python Paramiko log output of commands to a file
Don't use the paramiko logger. Rather create your own.
import logging
logger = logging.getLogger(__name__)
def restart_service(node_name):
print('='*30 + ' Starting to work on ' + node_name + ' ' + '='*30 + '\n')
logging.info('Connecting to %s in order to restart %s...', node_name, service_name)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.load_system_host_keys()
ssh.connect(node_name)
channel = ssh.get_transport().open_session()
channel.exec_command(command)
while True:
if channel.exit_status_ready():
break
rl, wl, xl = select.select([channel], [], [], 0.0)
if len(rl) > 0:
# Log output
logger.info(channel.recv(1024))
ssh.get_transport().close()
ssh.close()
This way you can have fine grained control about exactly what you want to log and which information is important to you
How to log each SSH session packet with Paramiko?
In addition to enabling logging, call Transport.set_hexdump()
:
client.get_transport().set_hexdump(True)
Regarding your original problem, see also:
Command executed with Paramiko does not produce any output
Related Topics
Prevent Sleep Mode Python (Wakelock on Python)
How to Get a List of All the Duplicate Items Using Pandas in Python
Shutting Down Computer (Linux) Using Python
Popen.Communicate() Throws Oserror: "[Errno 10] No Child Processes"
How to Search Directories and Find Files That Match Regex
How to Build 32Bit Python 2.6 on 64Bit Linux
Python Linux Dmidecode, How to Obtain Hw Info by Parsing
Python in Raw Mode Stdin Print Adds Spaces
Pickled File Won't Load on MAC/Linux
Python: Get Output of the Shell Command 'History'
Extract Text from Xml Documents in Python
Importerror: Matplotlib Is Required for Plotting When the Default Backend "Matplotlib" Is Selected
How to Use Method Overloading in Python
How Is the 'Is' Keyword Implemented in Python
Merge Lists That Share Common Elements