Gemensamma funktioner för att enklare undvika cirkulära importer

This commit is contained in:
2024-07-21 23:13:36 +02:00
parent 03c08d4024
commit 753353445c
+35
View File
@@ -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()")