Skip to content

Commit e704720

Browse files
authored
Merge pull request #8 from lunasleep/master
adding an option to override the timestamp field
2 parents 9cb2f8e + 522fb25 commit e704720

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

cmreshandler/cmreshandler.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class AuthType(Enum):
4343
__DEFAULT_ES_INDEX_NAME = 'python_logger'
4444
__DEFAULT_ES_DOC_TYPE = 'python_log'
4545
__DEFAULT_RAISE_ON_INDEXING_EXCEPTIONS = False
46+
__DEFAULT_TIMESTAMP_FIELD_NAME = "timestamp"
4647

4748
__LOGGING_FILTER_FIELDS = ['msecs',
4849
'relativeCreated',
@@ -60,7 +61,8 @@ def __init__(self,
6061
es_index_name=__DEFAULT_ES_INDEX_NAME,
6162
es_doc_type=__DEFAULT_ES_DOC_TYPE,
6263
es_additional_fields=__DEFAULT_ADDITIONAL_FIELDS,
63-
raise_on_indexing_exceptions=__DEFAULT_RAISE_ON_INDEXING_EXCEPTIONS):
64+
raise_on_indexing_exceptions=__DEFAULT_RAISE_ON_INDEXING_EXCEPTIONS,
65+
default_timestamp_field_name=__DEFAULT_TIMESTAMP_FIELD_NAME):
6466
""" Handler constructor
6567
6668
:param hosts: The list of hosts that elasticsearch clients will connect. The list can be provided
@@ -101,6 +103,7 @@ def __init__(self,
101103
self.es_additional_fields.update({'host': socket.gethostname(),
102104
'host_ip': socket.gethostbyname(socket.gethostname())})
103105
self.raise_on_indexing_exceptions = raise_on_indexing_exceptions
106+
self.default_timestamp_field_name = default_timestamp_field_name
104107

105108
self._buffer = []
106109
self._timer = None
@@ -203,7 +206,7 @@ def emit(self, record):
203206
for k, v in record.__dict__.items():
204207
if k not in CMRESHandler.__LOGGING_FILTER_FIELDS:
205208
rec[k] = "" if v is None else v
206-
rec['timestamp'] = self.__get_es_datetime_str(record.created)
209+
rec[self.default_timestamp_field_name] = self.__get_es_datetime_str(record.created)
207210

208211
self._buffer.append(rec)
209212
if len(self._buffer) >= self.buffer_size:

0 commit comments

Comments
 (0)