Skip to content
Browse files

HH-32313 fixed memory leak with gelfhandler

  • Loading branch information...
1 parent 777a3f3 commit b7704d71a1fa4afc26b971d60f43b61147e542bb @katraev katraev committed Mar 21, 2013
Showing with 34 additions and 31 deletions.
  1. +34 −31 frontik/frontik_logging.py
View
65 frontik/frontik_logging.py
@@ -10,6 +10,37 @@
from lxml.builder import E
try:
from graypy.handler import GELFHandler, LAN_CHUNK
+
+ class BulkGELFHandler(GELFHandler):
+
+ def handle_bulk(self, records_list, stages=None, status_code=None, exception=None, uri="None", method = "None", **kw):
+ if records_list != []:
+ first_record = records_list[0]
+ else:
+ self.close()
+ return
+ record_for_gelf = copy.deepcopy(first_record)
+ record_for_gelf.message = "{0} {1} {2} \n".format(record_for_gelf.asctime,record_for_gelf.levelname, record_for_gelf.message)
+ record_for_gelf.short = "{0} {1} {2}".format(method, uri, status_code)
+ record_for_gelf.exc_info = exception
+ record_for_gelf.levelno = 20
+ for record in records_list[1:]:
+ if record.levelno > record_for_gelf.levelno:
+ record_for_gelf.levelno = record.levelno
+ record_for_gelf.lineno = record.lineno
+ record_for_gelf.short = record.message
+ if record.exc_info is not None:
+ record_for_gelf.exc_info=traceback.format_exc(record.exc_info)
+ record.short += "\n" + traceback.format_exc(record.exc_info)
+ record_for_gelf.message += " {0} {1} {2} \n".format(record.asctime, record.levelname,record.message)
+ if stages is not None:
+ for stage_name, stage_start, stage_delta in stages:
+ setattr(record_for_gelf,stage_name+"_stage",str(int(stage_delta*1000)))
+ record_for_gelf.name = record_for_gelf.handler
+ record_for_gelf.code = status_code
+ GELFHandler.handle(self, record_for_gelf)
+ self.close()
+
except ImportError:
tornado.options.options.graylog = False
@@ -111,38 +142,9 @@ def flush(self, **kw):
self.addHandler = self.logger.addHandler
if tornado.options.options.graylog:
-
- class BulkGELFHandler(GELFHandler):
-
- def handle_bulk(self, records_list, stages=None, status_code=None, exception=None, **kw):
- if records_list != []:
- first_record = records_list[0]
- else:
- return
- record_for_gelf = copy.deepcopy(first_record)
- record_for_gelf.message = "{0} {1} {2} \n".format(record_for_gelf.asctime,record_for_gelf.levelname, record_for_gelf.message)
- record_for_gelf.short = "{0} {1} {2}".format(handler.request.method, handler.request.uri, status_code)
- record_for_gelf.exc_info = exception
- record_for_gelf.levelno = 20
- for record in records_list[1:]:
- if record.levelno > record_for_gelf.levelno:
- record_for_gelf.levelno = record.levelno
- record_for_gelf.lineno = record.lineno
- record_for_gelf.short = record.message
- if record.exc_info is not None:
- record_for_gelf.exc_info=traceback.format_exc(record.exc_info)
- record.short += "\n" + traceback.format_exc(record.exc_info)
- record_for_gelf.message += " {0} {1} {2} \n".format(record.asctime, record.levelname,record.message)
- if stages is not None:
- for stage_name, stage_start, stage_delta in stages:
- setattr(record_for_gelf,stage_name+"_stage",str(int(stage_delta*1000)))
- record_for_gelf.name = record.handler
- record_for_gelf.code = status_code
- GELFHandler.handle(self, record_for_gelf)
- self.close()
-
self.logger.add_bulk_handler(BulkGELFHandler(tornado.options.options.graylog_host,
tornado.options.options.graylog_port, LAN_CHUNK, False))
+
def stage_tag(self, stage_name):
zero_time = self.handler_started
self._stage_tag(PageLogger.Stage(stage_name, self._time - zero_time, time.time() - self._time))
@@ -174,7 +176,8 @@ def process(self, msg, kwargs):
return msg, kwargs
def request_finish_hook(self, exception = None):
- self.logger.flush(status_code=self.handler_ref()._status_code, stages=self.stages, exception=exception)
+ self.logger.flush(status_code=self.handler_ref()._status_code, stages=self.stages, exception=exception,
+ method=self.handler_ref().request.method, uri=self.handler_ref().request.uri)
def bootstrap_all_logging():
server_log = logging.getLogger("frontik.server")

0 comments on commit b7704d7

Please sign in to comment.
Something went wrong with that request. Please try again.