Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Paramiko logging?

I'm using Paramiko in Python to run command on a box through SSH. How to use Paramiko logging? I mean force it to make logs (in a file or terminal) and set the log level.

like image 699
Jason007 Avatar asked Dec 21 '14 08:12

Jason007


People also ask

How do I use Paramiko in Python?

A Paramiko SSH Example: Connect to Your Server Using a Password. This section shows you how to authenticate to a remote server with a username and password. To begin, create a new file named first_experiment.py and add the contents of the example file. Ensure that you update the file with your own Linode's details.

How do I disable Paramiko logging?

getLogger("paramiko"). setLevel(logging. WARNING) helps. (You can put this inside the module that's importing paramiko - just make sure the 'logging' module is enabled as well).

Does Paramiko use OpenSSH?

Paramiko does not itself leverage OpenSSH-style config file directives, but it does implement a parser for the format, which users can honor themselves (and is used by higher-level libraries, such as Fabric).

Why is Paramiko used?

Paramiko is a Python library that makes a connection with a remote device through SSh. Paramiko is using SSH2 as a replacement for SSL to make a secure connection between two devices. It also supports the SFTP client and server model.


2 Answers

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.

like image 92
Burhan Khalid Avatar answered Sep 26 '22 12:09

Burhan Khalid


paramiko.util.log_to_file("<log_file_path>", level = "WARN")
like image 31
ShawnLee Avatar answered Sep 23 '22 12:09

ShawnLee