Inject the environment into the LoggerConfigBuilder

This commit is contained in:
Rafa de la Torre 2016-10-03 17:06:57 +02:00
parent 18e1a5c7c9
commit 0d87a95270
2 changed files with 6 additions and 21 deletions

View File

@ -152,14 +152,13 @@ RETURNS Geometry AS $$
from cartodb_services.refactor.backend.redis_metrics_connection import RedisMetricsConnectionFactory
server_config_storage = InDbServerConfigStorage()
logger_config = LoggerConfigBuilder(server_config_storage).get()
logger = Logger(logger_config)
environment = ServerEnvironmentBuilder(server_config_storage).get()
user_config_backend = UserConfigBackendFactory(username, environment, server_config_storage).get()
org_config_backend = OrgConfigBackendFactory(orgname, environment, server_config_storage).get()
logger_config = LoggerConfigBuilder(environment, server_config_storage).get()
logger = Logger(logger_config)
mapzen_geocoder_config = MapzenGeocoderConfigBuilder(server_config_storage, user_config_backend, org_config_backend, username, orgname).get()
redis_metrics_connection = RedisMetricsConnectionFactory(environment, server_config_storage).get()

View File

@ -27,15 +27,13 @@ class LoggerConfig(object):
return self._min_log_level
# TODO this needs tests
# TODO FTM this is just config, maybe move around
class LoggerConfigBuilder(object):
def __init__(self, server_config_storage):
def __init__(self, environment, server_config_storage):
self._server_environment = environment
self._server_config_storage = server_config_storage
def get(self):
server_environment = self._get_server_environment()
logger_conf = self._server_config_storage.get('logger_conf')
if not logger_conf:
raise ConfigException('Logger configuration missing')
@ -44,21 +42,9 @@ class LoggerConfigBuilder(object):
log_file_path = self._get_value_or_none(logger_conf, 'log_file_path')
min_log_level = self._get_value_or_none(logger_conf, 'min_log_level') or 'warning'
logger_config = LoggerConfig(server_environment, rollbar_api_key, log_file_path, min_log_level)
logger_config = LoggerConfig(str(self._server_environment), rollbar_api_key, log_file_path, min_log_level)
return logger_config
def _get_server_environment(self):
server_config = self._server_config_storage.get('server_conf')
if not server_config:
environment = 'development'
else:
if 'environment' in server_config:
environment = server_config['environment']
else:
environment = 'development'
return environment
def _get_value_or_none(self, logger_conf, key):
value = None
if key in logger_conf: