Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to config flask app.logger from a configure file?

Is there any way to config flask app.logger from a configure file, like:

logging.config.fileConfig('/path/to/logging.cfg')

or

logging.config.dictConfig(config_dict)

So i can use app.logger.info('some message') to log both in develop and product mode.

like image 479
greatghoul Avatar asked Aug 05 '12 12:08

greatghoul


2 Answers

You need to call app.logger first and then logging.config.dictConfig(config_dict). The logger name should be the same in config_dict and in app.logger_name

like image 56
dughe Avatar answered Sep 20 '22 10:09

dughe


Change logging on line 22 to app.logger - that will configure the logger for your current Flask app. Alternately, you can use the logging module's getLogger function and use app.logger_name to pull the correct logger.

like image 27
Sean Vieira Avatar answered Sep 21 '22 10:09

Sean Vieira