-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
Description
flask.logger.create_logger() destroys any log handlers that have been added previously. Because the creation of the logger (and the calling of create_logger() that this entails) is deferred until the first time flask.app.logger is accessed, this can lead to the destruction of log handlers that were purposefully added by the application.
I just tracked down a bug due to this that took me a very long time to debug because I had no idea this went on. To my eyes, it looked like the standard logging module was breaking at a seemingly random moment (it wasn't even my code that was accessing app.logger, it was Flask's internal error handling code). Therefore, I think one of two courses of action should be taken:
- Because this behavior of
create_logger()seems very strange, perhaps it should be removed. As in don't delete log handlers that are already in place whencreate_logger()gets called. - If there is a good reason for this behavior to remain, it should be documented clearly in
app.logger's docstring.
I am happy to carry out either (or some other) change and send a pull request.