Book Image

Flask Framework Cookbook

By : Shalabh Aggarwal
Book Image

Flask Framework Cookbook

By: Shalabh Aggarwal

Overview of this book

Table of Contents (19 chapters)
Flask Framework Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Setting up basic file logging


By default, Flask will not log anything for us anywhere, except for the errors with their stack traces, which are sent to the logger (we will see more of this in the remaining part of the chapter). This creates a lot of stack traces when we run the application in the development mode using run.py, but in production systems, we don't have this luxury. Thankfully, the logging library provides a whole lot of log handlers, which can be used as per our requirements.

Getting ready

We will start with our catalog application and add some basic logging to it using FileHandler, which logs messages to a specified file on the filesystem. We will start with a basic log format and then see how to format the log messages to be more informative.

How to do it…

As always, the first change is made to the __init__.py file, which serves as the application's configuration file:

app.config['LOG_FILE'] = 'application.log'

if not app.debug:
    import logging
    from logging import FileHandler...