The app logs errors etc. to file and optionally can send an email whenever a message is logged. Different logging levels can be set for both by means of the respective environment variables. The available levels are those defined in the logging
module, i.e. CRITICAL
, ERROR
, WARNING
, INFO
, DEBUG
and NOTSET
.
The log files are automatically rolled over when their size reaches the value specified by the environment variable LOGGING_FILE_MAX_BYTES
. The number of backed up copies kept is set by the environment variable LOGGING_FILE_BACKUP_COUNT
. If LOGGING_FILE_MAX_BYTES
or LOGGING_FILE_BACKUP_COUNT
is 0, the log file is never rolled over. See the documentation for logging.handlers.RotatingFileHandler
for more details.
The logging handler are attached to the app. So in order to access them, you have to use code like the following.
from flask import current_app
current_app.logger.error('This is an error.')
current_app.logger.warning('This is a warning.')