3. Integrate Logger
import logginglogging.basicConfig( filename='app.log', # Log to a file called app.log level=logging.DEBUG, # Log messages of severity DEBUG and above format='%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]' )from flask import Flask, request app = Flask(__name__) @app.route('/') def home(): app.logger.debug('This is a debug message') app.logger.info('This is an info message') app.logger.warning('This is a warning message') app.logger.error('This is an error message') app.logger.critical('This is a critical message') return 'Hello, World!' if __name__ == '__main__': app.run(debug=True)
Example: Full Integration
Last updated