[Flask] How to wrest complete control of log output location from Flask?

Skip Montanaro skip.montanaro at gmail.com
Fri May 12 10:58:44 EDT 2017


In my Flask subclass, I override run() and set up self.logger just the
way I want it:

class FlaskApp(Flask):
    def run(self, ..., logfile):
        ...
        handler = FileHandler(logfile)
        handler.setFormatter(Formatter(...))
        self.logger.handlers = [handler]
        ...
    super(FlaskApp, self).run(...)

I guess in Flask.run it tacks on a StreamHandler instance, because all
my logging goes to my file, but the traditional web server log lines
still go to stdout or stderr. How do I make it stop that? I want
everything to go to the file I define.

Thx,

Skip Montanaro


More information about the Flask mailing list