What is the advantage of flask.logger over the more generic python logging module?

后端 未结 1 1050
别那么骄傲
别那么骄傲 2020-12-04 01:56

I\'m building a website using Flask and I\'m now in the process of adding some logging to it for which I found these docs. The basic example is as follows:

i         


        
相关标签:
1条回答
  • 2020-12-04 02:24

    The Flask logger uses the "generic" Python logging, it's a logging.getLogger(name) like any other.

    The logger exists so that Flask app and views can log things that happen during execution. For example, it will log tracebacks on 500 errors during debug mode. The configuration example is there to show how to enable these logs, which are still useful in production, when you are not in debug mode.

    Having an internal logger is not unique to Flask, it's the standard way to use logging in Python. Every module defines it's own logger, but the configuration of the logging is only handled by the last link in the chain: your project.

    You can also use app.logger for your own messages, although it's not required. You could also create a separate logger for your own messages. In the end, it's all Python logging.

    0 讨论(0)
提交回复
热议问题