How is the request log printed by flask in the console recorded in the log document?

I want to save the log output of the console when flask is running in the development environment to a file.
refers to the Internet, basically first configure logger and then add logger.info ("xxx") to the code to log.

what I want to achieve is that some of the requests output from the console and the logs printed by default are written directly to the log file.

the logger code I configured is as follows:

-sharpapp.__init__.py

def create_app(config_name):
    ...
    filehandler = logging.handlers.TimedRotatingFileHandler("flask.log", "M", 1, 0)
    filehandler.setLevel("DEBUG")
    app.logger.addHandler(filehandler
    ...
    

the logical effect should be to have a flask.log file generated, and then save another one every minute. The actual effect is that flask.log files are generated, but some requests and other information printed by the console are not available, and new logs are not automatically generated in time.

ask the great god to solve the doubt

Feb.24,2022

TimedRotatingFileHandler, your spelling is wrong. I can't find out the reason for your way of writing. After all, I've only been working for half a year. If I find the reason, please tell me, I can write this outside the factory function and record it:

  

how do I prevent the response of a request from being called to the console?

Menu