conn_with_logging.py
#!/usr/bin/env python
from netmiko import Netmiko
from getpass import getpass
import logging
logging.basicConfig(filename='D:\\netmiko-develop\\netmiko-develop\\examples\\use_cases\\case11_logging\\test.log', level=logging.DEBUG)
logger = logging.getLogger("netmiko")
cisco1 = {
'host': '10.0.1.7',
'username': 'admin',
'password': getpass(),
'device_type': 'cisco_ios',
}
net_connect = Netmiko(**cisco1)
print(net_connect.find_prompt())
net_connect.disconnect()
终端显示是这样的
image.png
test.log日志记录是这样的
DEBUG:paramiko.transport:starting thread (client mode): 0x68c42b0L
DEBUG:paramiko.transport:Local version/idstring: SSH