From e69a1318757255f9218c0a3265aae9cba7d05392 Mon Sep 17 00:00:00 2001 From: Joakim Persson Date: Sun, 28 Jul 2024 23:25:42 +0200 Subject: [PATCH] =?UTF-8?q?Fixat=20s=C3=A5=20att=20loggningen=20fungerar?= =?UTF-8?q?=20med=20GlobalState?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smartassist/src/startservices.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/smartassist/src/startservices.py b/smartassist/src/startservices.py index 684befb..7f05e6f 100644 --- a/smartassist/src/startservices.py +++ b/smartassist/src/startservices.py @@ -5,13 +5,13 @@ import yaml import json import socket import urllib.parse +from backend import run_flask import logging import utils -from utils import configure_logging -from backend import run_flask +from utils import GlobalState -configure_logging() # Configure root logger. The level will be adjusted later based on config file -logger = logging.getLogger(__name__) # Logger for this module, inherit properties of the root logger +global_state = GlobalState() # Configure root logger. The level will be adjusted later based on config file +logger = global_state.getLogger(__name__) # Logger for this module, inherit properties of the root logger def configure(): """ @@ -46,17 +46,10 @@ def configure(): # Extract global logging level #################################### if isinstance(updated_config.get('logging'), dict): # Look for 'logging' key in config file - # logging.info("found key 'logging' in config file") logging_config = updated_config['logging'] if isinstance(logging_config.get('level'), str): # Set to value of the yaml file if specified - # logging.info("found key 'level' in config file") - utils.log_level = logging_config['level'] - numeric_log_level = getattr(logging, utils.log_level, None) - - rlogger = logging.getLogger() # Get the root logger - rlogger.setLevel(numeric_log_level) - # set_local_logger(logger) # Set log level for logger based on log_level - logger.info("Global variable utils.log_level set to: {}".format(utils.log_level)) + global_state.set_log_level(logging_config['level']) + logger.debug("configure(): This logger now has effective log level %s", logger.getEffectiveLevel()) #################################### # Extract and export API endpoint as @@ -70,7 +63,7 @@ def configure(): api = updated_config['backend'].get('api') backend_api_ep = url+api # Extract API endpoint if defined logger.debug("BE_API_ENDPOINT is set to '{}'".format(backend_api_ep)) - os.environ['BE_API_ENDPOINT'] = backend_api_ep + os.environ['BE_API_ENDPOINT'] = backend_api_ep # Look into alternative way to share this with backend.py return updated_config @@ -113,6 +106,6 @@ def start_backend(config): if __name__ == '__main__': conf = configure() # Read config from file and set up config dict logger.debug('conf dictionary set to {}'.format(json.dumps(conf, indent=4))) - # start_frontend(config=conf) + # start_frontend(config=conf) # Not needed as we are using Flask for backend now start_backend(config=conf)