Fixat så att loggningen fungerar med GlobalState
This commit is contained in:
@@ -5,13 +5,13 @@ import yaml
|
|||||||
import json
|
import json
|
||||||
import socket
|
import socket
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
from backend import run_flask
|
||||||
import logging
|
import logging
|
||||||
import utils
|
import utils
|
||||||
from utils import configure_logging
|
from utils import GlobalState
|
||||||
from backend import run_flask
|
|
||||||
|
|
||||||
configure_logging() # Configure root logger. The level will be adjusted later based on config file
|
global_state = GlobalState() # 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
|
logger = global_state.getLogger(__name__) # Logger for this module, inherit properties of the root logger
|
||||||
|
|
||||||
def configure():
|
def configure():
|
||||||
"""
|
"""
|
||||||
@@ -46,17 +46,10 @@ def configure():
|
|||||||
# Extract global logging level
|
# Extract global logging level
|
||||||
####################################
|
####################################
|
||||||
if isinstance(updated_config.get('logging'), dict): # Look for 'logging' key in config file
|
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']
|
logging_config = updated_config['logging']
|
||||||
if isinstance(logging_config.get('level'), str): # Set to value of the yaml file if specified
|
if isinstance(logging_config.get('level'), str): # Set to value of the yaml file if specified
|
||||||
# logging.info("found key 'level' in config file")
|
global_state.set_log_level(logging_config['level'])
|
||||||
utils.log_level = logging_config['level']
|
logger.debug("configure(): This logger now has effective log level %s", logger.getEffectiveLevel())
|
||||||
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
|
# Extract and export API endpoint as
|
||||||
@@ -70,7 +63,7 @@ def configure():
|
|||||||
api = updated_config['backend'].get('api')
|
api = updated_config['backend'].get('api')
|
||||||
backend_api_ep = url+api # Extract API endpoint if defined
|
backend_api_ep = url+api # Extract API endpoint if defined
|
||||||
logger.debug("BE_API_ENDPOINT is set to '{}'".format(backend_api_ep))
|
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
|
return updated_config
|
||||||
|
|
||||||
@@ -113,6 +106,6 @@ def start_backend(config):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
conf = configure() # Read config from file and set up config dict
|
conf = configure() # Read config from file and set up config dict
|
||||||
logger.debug('conf dictionary set to {}'.format(json.dumps(conf, indent=4)))
|
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)
|
start_backend(config=conf)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user