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