简体   繁体   English

如何为导入的模块配置日志记录?

[英]How to configure logging for an imported module?

In my Superset web application, I am interested in setting the level of logging in Flask-OAuthLib to DEBUG .在我的Superset web 应用程序中,我有兴趣将 Flask-OAuthLib 的登录级别设置为DEBUG We can see Flask-OAuthLib access its logger here on line 26 from a Superset web application.我们可以看到 Flask-OAuthLib 在第 26 行从 Superset web 应用程序访问其记录器。

Superset is a web application implemented using Flask-AppBuilder . Superset 是使用Flask-AppBuilder实现的 web 应用程序。 It allows for OAuth2 authentication via Flask-OAuthLib.它允许通过 Flask-OAuthLib 进行 OAuth2 身份验证。

I want to configure Flask-OAuthLib logging from custom_sso_security_manager.py ... a module described in the Superset docs on custom OAuth configuration .我想从custom_sso_security_manager.py配置 Flask-OAuthLib 日志记录... 在自定义 OAuth 配置的 Superset 文档中描述的模块。

You can access the logger in exactly the same way.您可以以完全相同的方式访问记录器。 They are added to a global dictionary that items can be get from with getLogger(key) .它们被添加到全局字典中,可以使用getLogger(key)从中获取项目。 So all you need is put something like this into your file after you imported the oauth lib:因此,您只需在导入 oauth 库后将类似内容放入文件中:

oauth_logger = logging.getLogger('flask_oauthlib')
oauth_logger.setLevel(logging.DEBUG)

# it is custom for libs to have no handler (except the NullHandler)
# so you may want to add one:
oauth_logger.addHandler(logging.StreamHandler()) # just an example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM