简体   繁体   中英

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 . We can see Flask-OAuthLib access its logger here on line 26 from a Superset web application.

Superset is a web application implemented using Flask-AppBuilder . It allows for OAuth2 authentication via Flask-OAuthLib.

I want to configure Flask-OAuthLib logging from custom_sso_security_manager.py ... a module described in the Superset docs on custom OAuth configuration .

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) . So all you need is put something like this into your file after you imported the oauth lib:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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