From 753353445c2cccc37f0b8fce20c9327fb9273a1b Mon Sep 17 00:00:00 2001 From: Joakim Persson Date: Sun, 21 Jul 2024 23:13:36 +0200 Subject: [PATCH] =?UTF-8?q?Gemensamma=20funktioner=20f=C3=B6r=20att=20enkl?= =?UTF-8?q?are=20undvika=20cirkul=C3=A4ra=20importer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smartassist/src/utils.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 smartassist/src/utils.py 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