Python 如何使用 Paramiko 日志记录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27587716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use Paramiko logging?
提问by Jason007
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.
我在 Python 中使用 Paramiko 通过 SSH 在一个盒子上运行命令。如何使用 Paramiko 日志记录?我的意思是强制它制作日志(在文件或终端中)并设置日志级别。
采纳答案by Burhan Khalid
Paramiko names its loggers, so simply:
Paramiko 命名它的记录器,很简单:
import logging
import paramiko
logging.basicConfig()
logging.getLogger("paramiko").setLevel(logging.WARNING) # for example
See the logging cookbookfor some more examples.
有关更多示例,请参阅日志记录手册。
You can also use log_to_file
from paramiko.util
to log directly to a file.
您还可以使用log_to_file
fromparamiko.util
直接登录到文件。
回答by ShawnLee
paramiko.util.log_to_file("<log_file_path>", level = "WARN")