July 2019
Beginner to intermediate
302 pages
9h 38m
English
The information logged does not help much. It will be great to know when the issue was logged, with what level, which file caused the issue at what line number, and so on. This can be achieved using advanced logging formats. For this, we need to add a couple of statements to the configuration file; that is, my_app/__init__.py:
if not app.debug:
import logging logging.basicConfig(level=logging.WARNING)
from logging import FileHandler, Formatter
file_handler = FileHandler(app.config['LOG_FILE'])
app.logger.addHandler(file_handler)
file_handler.setFormatter(Formatter(
'%(asctime)s %(levelname)s: %(message)s '
'[in %(pathname)s:%(lineno)d]'
))
In the preceding code, we added a formatter to file_handler, which will log the time, ...
Read now
Unlock full access