This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/data/logs_model/__init__.py

42 lines
1.3 KiB
Python
Raw Normal View History

import os
import logging
from data.logs_model.table_logs_model import TableLogsModel
from data.logs_model.document_logs_model import DocumentLogsModel
from data.logs_model.table_document_transition_logs_model import TableDocumentTransitionLogsModel
from data.logs_model.elastic_logs import AWSElasticsearchLogs
from data.logs_model.interface import ActionLogsDataInterface
logger = logging.getLogger(__name__)
_LOG_MODELS = {
'database': TableLogsModel,
'transition': TableDocumentTransitionLogsModel,
'elasticsearch': DocumentLogsModel,
}
class LogsModelProxy(object):
def __init__(self):
self._model = None
def initialize(self, model):
self._model = model
logger.info('===============================')
logger.info('Using logs model `%s`', self._model)
logger.info('===============================')
def __getattr__(self, attr):
if not self._model:
raise AttributeError("LogsModelProxy is not initialized")
return getattr(self._model, attr)
logs_model = LogsModelProxy()
def configure(config_object):
logger.debug('Configuring Log Model')
model = config_object.get('LOGS_MODEL', ('database', {}))
model_name = model[0]
params = {} if len(model) == 1 else model[1]
logs_model.initialize(_LOG_MODELS[model_name](**params))