diff --git a/graypy/handler.py b/graypy/handler.py index 1a124fa17..412557932 100644 --- a/graypy/handler.py +++ b/graypy/handler.py @@ -287,8 +287,19 @@ def smarter_repr(obj): """Convert JSON incompatible object to string""" if isinstance(obj, datetime.datetime): return obj.isoformat() + return repr(obj) +def introspective_repr(obj): + """ introspective repr() - alternative to smarter_repr() """ + + if isinstance(obj, datetime.datetime): + return obj.isoformat() + + if isinstance(obj, enum.Enum): + return repr({obj.name: obj.value}) + + return repr(dir(obj)) def message_to_pickle(obj): """Convert object to a JSON-encoded string""" diff --git a/graypy/rabbitmq.py b/graypy/rabbitmq.py index d687bf064..3a806e56a 100644 --- a/graypy/rabbitmq.py +++ b/graypy/rabbitmq.py @@ -5,6 +5,7 @@ handler""" import json +from graypy.handler import make_message_dict, introspective_repr from logging import Filter from logging.handlers import SocketHandler @@ -85,7 +86,11 @@ def makePickle(self, record): self.localname, self.facility ) - return json.dumps(message_dict) + + try: + return json.dumps(message_dict) + except TypeError: + return json.dumps(message_dict, default=introspective_repr) class RabbitSocket(object):