Browse Source

get logging level from config

master
rozetko 4 years ago
parent
commit
333f53b93e
  1. 26
      analytics/config.py

26
analytics/config.py

@ -11,20 +11,30 @@ if config_exists:
with open(CONFIG_FILE) as f: with open(CONFIG_FILE) as f:
config = json.load(f) config = json.load(f)
else: else:
print('Config file %s doesn`t exist, using defaults' % CONFIG_FILE) print('Config file %s doesn`t exist, using environment variables / defaults' % CONFIG_FILE)
def get_config_field(field: str, default_val = None): def get_config_field(field: str, default_val = None, allowed_values = []):
value = None
if field in os.environ: if field in os.environ:
return os.environ[field] value = os.environ[field]
elif config_exists and field in config and config[field] != '':
value = config[field]
elif default_val is not None:
value = default_val
if config_exists and field in config and config[field] != '': if len(allowed_values) > 0 and value not in allowed_values:
return config[field] raise Exception('{} value must be one of: {}, got: {}'.format(field, allowed_values, value))
if default_val is not None: if value == None:
return default_val raise Exception('Please configure {}'.format(field))
raise Exception('Please configure {}'.format(field)) return value
HASTIC_SERVER_URL = get_config_field('HASTIC_SERVER_URL', 'ws://localhost:8002') HASTIC_SERVER_URL = get_config_field('HASTIC_SERVER_URL', 'ws://localhost:8002')
LOGGING_LEVEL = get_config_field(
'HS_AL_LOGGING_LEVEL',
'INFO',
['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
)
LEARNING_TIMEOUT = get_config_field('LEARNING_TIMEOUT', 120) LEARNING_TIMEOUT = get_config_field('LEARNING_TIMEOUT', 120)

Loading…
Cancel
Save