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

Gergely Polonkai gergely at polonkai.eu
Fri May 12 12:04:07 EDT 2017


Take a look at Flask-Logging-Extras, which does exactly that, but without
overriding Flask methods:

https://pypi.python.org/pypi/Flask-Logging-Extras

You may or may not like its functionality, but looking at its source code
will answer your question.

On Fri, May 12, 2017, 16:58 Skip Montanaro <skip.montanaro at gmail.com> wrote:

> 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
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20170512/141aa1b9/attachment.html>


More information about the Flask mailing list