Turning off logging in Paramiko

前端 未结 3 745
广开言路
广开言路 2021-02-05 07:38

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

import paramiko         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-05 08:04

    You're setting the root logger's level to WARN (should be WARNING) in remoteConnect.py, and to INFO in getdata.py. I would advise that you avoid setting levels on the root logger in random modules in your application: instead, do this in all your modules where you want to use logging:

    import logging
    
    logger = logging.getLogger(__name__)
    

    and use logger.debug(...), etc. in that module. Then, in one specific place in your application (typically in your logic called from if __name__ == '__main__':, set the levels and handlers that you want, either programmatically via basicConfig or a set of API calls to add handlers, formatters etc., or through the use of a declarative configuration (e.g. using fileConfig or dictConfig APIs - documented here).

提交回复
热议问题