Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 'level_names' for 'GELFRabbitHandler' #88

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=================
Expand Down
8 changes: 6 additions & 2 deletions graypy/rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions perftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = {
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down