Fixat så att loggningen fungerar med GlobalState
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user