Skip to content
Advertisement

Logger not creating logs on log file in flask application;

I want to create logs in my log file, logs can be shown on the terminal but not written on the log files. I created a package imp_calc which has templates and other files inside it, accessing it using run.py which accesses the imp_calc package’s modules. My folder structure is as follows:

JavaScript

my init.py file

JavaScript

My Routes Folder through which I want to throw my logs

JavaScript

my run.py

JavaScript

Advertisement

Answer

You are using app.logger inside route. But basicConfig does basic configuration for the logging system by creating a StreamHandler with a default Formatter and adding it to the root logger.

You can use dictConfig to configure loggers / handlers / formatters. Here is an example:

JavaScript

Open http://localhost:5000/. You’ll see stdout logs:

JavaScript

Let’s check file logs(cat debug.log):

JavaScript

So just use dictConfig.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement