24

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.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Jason007
  • 288
  • 1
  • 2
  • 6

2 Answers2

36

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.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
10
paramiko.util.log_to_file("<log_file_path>", level = "WARN")
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
ShawnLee
  • 157
  • 2
  • 9