Python Flask writes access log to STDERR

The flag writes access logs to the STDERR stream instead of STDOUT. How to change this configuration so that access logs go to STDOUT and application errors in STDERR?

open-cricket [master] python3 flaskr.py > stdout.log 2> stderr.log & [1] 11929 open-cricket [master] tail -f stderr.log * Running on http://127.0.0.1:9001/ 127.0.0.1 - - [11/Mar/2015 16:23:25] "GET /?search=Sachin+Tendulkar+stats HTTP/1.1" 200 - 127.0.0.1 - - [11/Mar/2015 16:23:25] "GET /favicon.ico HTTP/1.1" 404 - 
+6
source share
2 answers

Here is what you have to do. Import logging and set the level you need to record.

 import logging log = logging.getLogger('werkzeug') log.setLevel(logging.ERROR) 
+4
source

I assume that you are using a flash development server.

The flag development server is based on werkzeug , whose WSGIRequestHandler , in turn, is based on BaseHTTPServer in the standard lib library.

As you have noticed, WSGIRequestHandler overrides the logging methods log_request , log_error and log_message to use this own logging.Logger - so you can simply override it as you like in the spirit of Ijad's response.

If you go down this route, I think it would be easier to add your own FileHandler , and separate the output from stdout and stderr using a filter

Please note, however, that all this is very implementation specific - in fact, there is no proper interface for doing what you want .

Although this concerns your actual question, I feel that I really have to ask - why are you worried about what is included in each log on the development server ?

If you encounter such a problem, should you not run a real web server already ?

+4
source

Source: https://habr.com/ru/post/983642/


All Articles