diff --git a/smartassist/src/utils.py b/smartassist/src/utils.py new file mode 100644 index 0000000..b0eff29 --- /dev/null +++ b/smartassist/src/utils.py @@ -0,0 +1,35 @@ +# This module contains definitions of variables, functions, classes, et cetera, that are +# imported to more than one other module. The rational for defining these things here +# is that it is easier to avoid circular imports when they are defined in a central location. +import logging + +global log_level +log_level = 'INFO' + +logger = logging.getLogger(__name__) + +def set_local_logger(log_instance): + """ + Configure logging based on the global variable log_level + Logging is controlled by integer values, where DEBUG < INFO < WARNING < ERROR < CRITICAL. + To turn off logging completely, set numeric_log_level to at least CRITICAL + 1. + """ + global log_level + numeric_log_level = getattr(logging, log_level, None) + if not isinstance(numeric_log_level, int): + raise ValueError('Invalid log level: %s' % log_level) + + logging.basicConfig(level=numeric_log_level) # Set the root logger level to the configured level + log_instance.info('Log level set to {}'.format(log_level)) # Example usage of the logger + + +def run_flask(app, fport=5005): + """ + Starts the Flask server + """ + # Flask endpoint for user interaction + logger.debug("Entering run_flask()") + # app.run(port = str(str(fport)), debug=False) + app.run(port = str(str(fport)), debug=True) + # app.run(port=5000, debug=True, use_reloader=False) + logger.debug("Exiting run_flask()") \ No newline at end of file