diff --git a/README.rst b/README.rst index 6a96f8ceb..20915d580 100644 --- a/README.rst +++ b/README.rst @@ -103,6 +103,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 23301bf6c..8f7224327 100644 --- a/graypy/rabbitmq.py +++ b/graypy/rabbitmq.py @@ -40,12 +40,14 @@ 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=''): + localname=None, facility=None, level_names=False, + virtual_host='/', routing_key=''): self.url = url parsed = urlparse(url) if parsed.scheme != 'amqp': @@ -68,6 +70,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) @@ -84,6 +87,7 @@ def makePickle(self, record): self.extra_fields, self.fqdn, self.localname, + self.level_names, self.facility ) return json.dumps(message_dict) diff --git a/perftest.py b/perftest.py index dc3f9f8ed..9810adce8 100755 --- a/perftest.py +++ b/perftest.py @@ -63,6 +63,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/setup.py b/setup.py index 898440895..99718f84c 100755 --- a/setup.py +++ b/setup.py @@ -64,6 +64,7 @@ def run_tests(self): "pytest-cov", "pylint>=1.9.1,<2.0.0", "mock>=2.0.0,<3.0.0", + "amqplib", ], extras_require={'amqp': ['amqplib==1.0.2']}, classifiers=[