简体   繁体   中英

python application changing logging level

I have a python package and the logging level is set as below (in app.py).

logger = logging.getLogger('app')
logger.handlers = []
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.ERROR)

logging.getLogger("requests").setLevel(logging.WARNING)

I generally import this module DbApp (from app.py) and directly run it. As this package is installed using pip, I don't want to change the logging level in the file.

How can I change from my main program to set the logging level?

from db.rest import DbApp    
app = DbApp()

I believe you can set the logging level dynamically using the setLevel API. As an example: logger.setLevel(logging.DEBUG)

For further info, you may refer to : https://docs.python.org/2/library/logging.html

Hope it helps.

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