Python 3 Flask Logging Module to Print Log Messages in Console or Terminal

Python 3 Flask Logging Module to Print Log Messages in Console or Terminal Article has many meanings. We are going to know this topic clearly through this article. We hope you like this article.

Python Standard Library comes with a log module that provides most of the basic log features. By setting it up correctly, a recording message can bring a lot of useful information about when and where it is being recorded, as well as a recording environment such as the running process/thread.

Python 3 Flask Logging Module to Print Log Messages in Console or Terminal

Python 3 Flask Logging Module to Print Log Messages in Console or Terminal

pip install flask

After installing the 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

Python 3 Flask Logging Module to Print Log Messages in Console or Terminal

Read Also: Python 3 Flask Upload Multiple Files or Images Using HTML5 Form in Browser

Final Words

Python 3 Flask Logging Module to Print Log Messages in Console or Terminal We got to know our topic very clearly. And if you have any doubts about this article you can let us know your doubts via comment.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment