Flask Logging
Logging is a very usefule tool to avoid the need for manual debugging. It also can provide insight as to what happened
in a session on the production server. During development you'll be able to see the messages on the terminal where Flask runs.
On the production server it can be saved in a log file for later review.
There are several pre-defined levels of logging. You can use the specific functions to indicate the importance of each log message.
You can set the level of logging inside the code or in an external configuration file.
examples/flask/log/app.py
from flask import Flask import logging app = Flask(__name__) # minimum log level defaults to warning # we can set the minimum loge level app.logger.setLevel(logging.INFO) app.logger.debug('debug') app.logger.info('info') app.logger.warning('warning') @app.route("/") def main(): app.logger.debug("Some debug message") app.logger.info("Some info message") app.logger.warning("Some warning message") app.logger.error("Some error message") return "Hello World"