Skip to content

Design issue with flask.logger.create_logger(). #641

@itsjohncs

Description

@itsjohncs

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 when create_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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions