2121except ImportError :
2222 AWS4AUTH_SUPPORTED = False
2323
24+ from serializers import CMRESSerializer
25+
2426
2527class CMRESHandler (logging .Handler ):
2628 """ Elasticsearch log handler
@@ -196,8 +198,8 @@ def __init__(self,
196198 self ._client = None
197199 self ._buffer = []
198200 self ._timer = None
199-
200201 self ._index_name_func = CMRESHandler ._INDEX_FREQUENCY_FUNCION_DICT [self .index_name_frequency ]
202+ self .serializer = CMRESSerializer ()
201203
202204 def __schedule_flush (self ):
203205 if self ._timer is None :
@@ -211,7 +213,8 @@ def __get_es_client(self):
211213 self ._client = Elasticsearch (hosts = self .hosts ,
212214 use_ssl = self .use_ssl ,
213215 verify_certs = self .verify_certs ,
214- connection_class = RequestsHttpConnection )
216+ connection_class = RequestsHttpConnection ,
217+ serializer = self .serializer )
215218 return self ._client
216219
217220 if self .auth_type == CMRESHandler .AuthType .BASIC_AUTH :
@@ -220,7 +223,8 @@ def __get_es_client(self):
220223 http_auth = self .auth_details ,
221224 use_ssl = self .use_ssl ,
222225 verify_certs = self .verify_certs ,
223- connection_class = RequestsHttpConnection )
226+ connection_class = RequestsHttpConnection ,
227+ serializer = self .serializer )
224228 return self ._client
225229
226230 if self .auth_type == CMRESHandler .AuthType .KERBEROS_AUTH :
@@ -231,7 +235,8 @@ def __get_es_client(self):
231235 use_ssl = self .use_ssl ,
232236 verify_certs = self .verify_certs ,
233237 connection_class = RequestsHttpConnection ,
234- http_auth = HTTPKerberosAuth (mutual_authentication = DISABLED ))
238+ http_auth = HTTPKerberosAuth (mutual_authentication = DISABLED ),
239+ serializer = self .serializer )
235240
236241 if self .auth_type == CMRESHandler .AuthType .AWS_SIGNED_AUTH :
237242 if not AWS4AUTH_SUPPORTED :
@@ -243,7 +248,8 @@ def __get_es_client(self):
243248 http_auth = awsauth ,
244249 use_ssl = self .use_ssl ,
245250 verify_certs = True ,
246- connection_class = RequestsHttpConnection
251+ connection_class = RequestsHttpConnection ,
252+ serializer = self .serializer
247253 )
248254 return self ._client
249255
@@ -309,11 +315,13 @@ def close(self):
309315 def emit (self , record ):
310316 """ Emit overrides the abstract logging.Handler logRecord emit method
311317
312- records the log
318+ Format and records the log
313319
314320 :param record: A class of type ```logging.LogRecord```
315321 :return: None
316322 """
323+ self .format (record )
324+
317325 rec = self .es_additional_fields .copy ()
318326 for key , value in record .__dict__ .items ():
319327 if key not in CMRESHandler .__LOGGING_FILTER_FIELDS :
0 commit comments