Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

HH-32313 graylog handler fixes

  • Loading branch information...
commit 43905a17608eaffaaab72482a472b994fb41551b 1 parent 0a6aaac
@katraev katraev authored
Showing with 33 additions and 32 deletions.
  1. +1 −1  debian/control
  2. +32 −31 frontik/frontik_logging.py
View
2  debian/control
@@ -18,5 +18,5 @@ Depends: ${shlibs:Depends}, ${misc:Depends},
python-tornado (>= 2.0~hh7),
python-tornado-util (>= 0.5.1),
python,
-Suggests: python-graypy, watchdog,
+Suggests: python-graypy=1.0+hh3, watchdog,
Description: frontik - the python based XScript alternative
View
63 frontik/frontik_logging.py
@@ -1,13 +1,12 @@
# -*- coding: utf-8 -*-
from collections import namedtuple
import copy
-
+import tornado.options
import logging
from logging.handlers import SysLogHandler
import traceback
import weakref
import time
-import tornado.options
from lxml.builder import E
try:
from graypy.handler import GELFHandler, LAN_CHUNK
@@ -40,35 +39,6 @@ def __get_logfile_name(self):
logfile_parts.insert(1, 'monik')
return '.'.join(logfile_parts)
-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.exc_info = exception
- 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.filename=record.filename
- if record.exc_info is not None:
- record_for_gelf.exc_info=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,str(stage_delta - stage_start))
-
- record_for_gelf.code = status_code
- GELFHandler.handle(self, record_for_gelf)
- self.close()
-
-
class MaxLenSysLogHandler(SysLogHandler):
"""
Extension of standard SysLogHandler with possibility to limit log message sizes
@@ -141,6 +111,37 @@ 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)
+ setattr(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:]:
+ print record.levelno, record_for_gelf.levelno
+ 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):
Please sign in to comment.
Something went wrong with that request. Please try again.