Python 3 Flask Logging Module to Print Log Messages in Console or Terminal Full Project For Beginners

 

 

pip install flask

 

 

After installing flask make an app.py file and copy paste the following code

 

 

app.py

 

 

from flask import Flask
import logging
 
app = Flask(__name__)
 
logging.basicConfig(filename='record.log', level=logging.DEBUG, format=f'%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s')
 
@app.route('/blogs')
def blog():
    app.logger.info('Info level log')
    app.logger.warning('Warning level log')
    return f"Welcome to the Blog"
 
app.run(host='localhost', debug=True)

 

 

Now if you run your flask app by typing the below command

 

 

python app.py

 

 

Leave a Reply