Logging - QuinnBast/SaskTel-Communication-Portal GitHub Wiki
When a flask server begins, it has the capability to log messages to the console as well as log messages to a log file. Configuring the built-in Flask logging system is extremely complex to configure the smallest change, however, this guide should provide an example of how to make changes to the logging system if needed. If more information is needed, view the Flask logging documentation.
Flask logging is done through a Yaml configuration file. This configuration file handles logging for not only log files, but also logging to the console as well as log formats. In order to change the default log file, you will need to find the handlers.file.filename
Yaml configuration. Changing the filepath in this location will change what file is used as the log file.
In order to add custom debugging messages to the application's console or logs, you will need to import the respective messaging module.
To send messages to the console, from REST.server import logconsole
to import the console messenger.
To send messages to the log file, from REST.server import logfile
to import the log messenger.
In order to send a message to the module, use the functions outlined below, where 'module' is the imported module indicated above.
module.DEBUG("Your Message Here") -- sends your message with DEBUG priority level.
module.INFO("Your Message Here") -- sends your message with INFO priority level.
module.WARNING("Your Message Here") -- sends your message with WARNING priority level.
module.ERROR("Your Message Here") -- sends your message with ERROR priority level.
module.CRITICAL("Your Message Here") -- sends your message with CRITICAL priority level.
NOTE: If the Flask server has been configured to not output console or logging information, then the information will not be logged as no messenger is configured to send messages. Ensure that before sending a message, you check if the configuration is enabled. To check if a configuration is enabled, import the configuration module from REST.server import config
.
To check if logging is enabled: if config.logging: # output to file here
To check if console output is enabled: if config.verbose: # output to console here