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/logs_producer/elasticsearch_logs_producer.py
2019-11-12 11:09:47 -05:00

25 lines
989 B
Python

import logging
from elasticsearch.exceptions import ElasticsearchException
from data.logs_model.logs_producer.interface import LogProducerInterface
from data.logs_model.logs_producer import LogSendException
logger = logging.getLogger(__name__)
class ElasticsearchLogsProducer(LogProducerInterface):
""" Log producer writing log entries to Elasticsearch.
This implementation writes directly to Elasticsearch without a streaming/queueing service.
"""
def send(self, logentry):
try:
logentry.save()
except ElasticsearchException as ex:
logger.exception('ElasticsearchLogsProducer error sending log to Elasticsearch: %s', ex)
raise LogSendException('ElasticsearchLogsProducer error sending log to Elasticsearch: %s' % ex)
except Exception as e:
logger.exception('ElasticsearchLogsProducer exception sending log to Elasticsearch: %s', e)
raise LogSendException('ElasticsearchLogsProducer exception sending log to Elasticsearch: %s' % e)