关闭Paramiko中的日志记录

关闭Paramiko中的日志记录

本文介绍了关闭Paramiko中的日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Paramiko提供的ssh客户端来创建函数调用remoteSSH(文件名为remoteConnect.py):

I am using the ssh client provided by Paramiko to create a function call remoteSSH (the file name is remoteConnect.py):

import paramiko
import logging
logger = paramiko.util.logging.getLogger()
logger.setLevel(logging.WARN)

def remoteSSH(username,userpasswd):
    ....

现在我在另一个称为getData()(getdata.py)的Python模块中调用remoteSSH函数:

Now I am calling the remoteSSH function in another Python module called getData() (getdata.py):

from remoteConnect import *
import logging
logger2=logging.getLogger()
logger2.setLevel(logging.INFO)

但是,对logger2.info('ccc')的调用也会在导入Paramiko模块(即remoteConnect.py)的文件中打开所有INFO级别的日志记录

However, a call to logger2.info('ccc') also turns on all INFO level logging in the file that is importing the Paramiko module (i.e. remoteConnect.py)

如何关闭登录remoteConnect.py的权限,以使Paramiko不会吐出所有INFO级别的消息?

How do I turn off logging in remoteConnect.py so that Paramiko does not spit out all the INFO level messages?

推荐答案

Paramiko将其命名为Logggers.它似乎可以充当其他语言的日志记录模块(可以想到JDK日志记录).

Paramiko names its logggers. It seems to function as the logging modules in other languages (JDK logging comes to mind) do.

我发现了

logging.getLogger("paramiko").setLevel(logging.WARNING)帮助.

(您可以将其放在导入paramiko的模块内-只需确保同时启用了日志记录"模块即可.)

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

花了我一段时间才知道如何做到这一点(事实上,直到我真正开始处理Java日志记录时,我才想到这个答案)

It took me a while to figure out how to do this (in fact, it wasn't until I actually started dealing with Java logging that this answer came to mind)

这篇关于关闭Paramiko中的日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 01:00