From 304b90900f732a91e2dca19ed08e46773e6dd566 Mon Sep 17 00:00:00 2001 From: Liang Chen Date: Tue, 25 Sep 2018 13:07:35 -0400 Subject: [PATCH 1/3] add optional argument 'level_names' for 'graypy.GELFRabbitHandler' --- README.rst | 1 + graypy/rabbitmq.py | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 2a357776b..82caaa2e8 100644 --- a/README.rst +++ b/README.rst @@ -101,6 +101,7 @@ GELFRabbitHandler: * **exchange_type** - RabbitMQ exchange type (default `fanout`). * **localname** - use specified hostname as source host. * **facility** - replace facility with specified value. if specified, record.name will be passed as `logger` parameter. + * **level_names** - allows the use of string error level names instead in addition to their numerical representation. Using with Django ================= diff --git a/graypy/rabbitmq.py b/graypy/rabbitmq.py index d519067f9..32dd39fbd 100644 --- a/graypy/rabbitmq.py +++ b/graypy/rabbitmq.py @@ -32,11 +32,13 @@ class GELFRabbitHandler(SocketHandler): :param localname: Use specified hostname as source host. :param facility: Replace facility with specified value. If specified, record.name will be passed as `logger` parameter. + :param level_names: Allows the use of string error level names instead + of numerical values. Defaults to False """ def __init__(self, url, exchange='logging.gelf', debugging_fields=True, extra_fields=True, fqdn=False, exchange_type='fanout', localname=None, - facility=None, virtual_host='/', routing_key=''): + facility=None, level_names=False, virtual_host='/', routing_key=''): self.url = url parsed = urlparse(url) if parsed.scheme != 'amqp': @@ -58,6 +60,7 @@ def __init__(self, url, exchange='logging.gelf', debugging_fields=True, self.exchange_type = exchange_type self.localname = localname self.facility = facility + self.level_names = level_names self.virtual_host = virtual_host self.routing_key = routing_key SocketHandler.__init__(self, host, port) @@ -69,8 +72,8 @@ def makeSocket(self, timeout=1): def makePickle(self, record): message_dict = make_message_dict( - record, self.debugging_fields, self.extra_fields, self.fqdn, self.localname, - self.facility) + record, self.debugging_fields, self.extra_fields, self.fqdn, + self.localname, self.level_names, self.facility) return json.dumps(message_dict) From 6937c0585d71eade86bccceba172f5ecab6c9b79 Mon Sep 17 00:00:00 2001 From: Liang Chen Date: Tue, 25 Sep 2018 13:07:58 -0400 Subject: [PATCH 2/3] update unittest for the missing dependency --- perftest.py | 5 +++++ tox.ini | 1 + 2 files changed, 6 insertions(+) diff --git a/perftest.py b/perftest.py index e40211d7d..502a449a7 100755 --- a/perftest.py +++ b/perftest.py @@ -60,6 +60,11 @@ def main(argv=sys.argv): 'formatter': 'message', } config['root']['handlers'].append('graylog_rabbit') + try: + from amqplib import client_0_8 as amqp + except ImportError: + msg = "Unable to test GELFRabbitHandler due to missing external dependency: amqplib" + raise RuntimeError(msg) if args.console_logger: config['handlers']['console'] = { diff --git a/tox.ini b/tox.ini index bafaccb35..1adb7e1f1 100644 --- a/tox.ini +++ b/tox.ini @@ -8,3 +8,4 @@ commands = deps = pytest mock + amqplib From 7b47fd0b9288b9fef9616df73e4cb089ca3eb326 Mon Sep 17 00:00:00 2001 From: Liang Chen Date: Sat, 27 Oct 2018 21:29:33 -0400 Subject: [PATCH 3/3] add test dependency --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 139ac019f..2ec641497 100755 --- a/setup.py +++ b/setup.py @@ -64,7 +64,8 @@ def run_tests(self): "pytest-timeout", "pylint>=1.9.1,<2.0.0", "mock>=2.0.0,<3.0.0", - "tox>=3.4.0,<4.0.0" + "tox>=3.4.0,<4.0.0", + "amqplib", ], extras_require={'amqp': ['amqplib==1.0.2']}, classifiers=[