From 61974859bd5be09a87fcf05d798ee75f71ac8d3f Mon Sep 17 00:00:00 2001 From: Joakim Persson Date: Wed, 24 Jul 2024 17:22:58 +0200 Subject: [PATCH] =?UTF-8?q?Fixat=20loggningen.=20Olika=20tester=20av=20hur?= =?UTF-8?q?=20=20information=20kan=20f=C3=B6ras=20=C3=B6ver=20till=20front?= =?UTF-8?q?end.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smartassist/src/startservices.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/smartassist/src/startservices.py b/smartassist/src/startservices.py index 37b6719..8bf5d68 100644 --- a/smartassist/src/startservices.py +++ b/smartassist/src/startservices.py @@ -7,10 +7,11 @@ import socket import urllib.parse import logging import utils -from utils import set_local_logger +from utils import configure_logging from backend import run_flask -logger = logging.getLogger(__name__) # Logger for this module +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 def configure(): """ @@ -45,13 +46,32 @@ 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'] - logger.info("Logging level set to: {}".format(utils.log_level)) - - set_local_logger(logger) # Set log level for logger based on log_level - logger.debug("Logging level of startservices' logger has been configured") + 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)) + + #################################### + # Extract and export API endpoint as + # envrionment variable + #################################### + backend_api_ep = 'http://localhost:5005/api/chat' # Default API endpoint + if isinstance(updated_config.get('backend'), dict): # Look for 'backend' key in config file + if isinstance(updated_config['backend'].get('url'), str): # Look for 'url' key in config file + url = updated_config['backend'].get('url') + if isinstance(updated_config['backend'].get('api'), str): # Look for 'api' key in config file + 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 + return updated_config