Commit dba03b9c by Carlos Andrés Rocha

Merge pull request #953 from rocha/fix-event-logger-backend-json-encoding

Fix error encoding datetime objects in the event track logger backend
parents 4b07aa0f 979ec89f
...@@ -33,7 +33,7 @@ class LoggerBackend(BaseBackend): ...@@ -33,7 +33,7 @@ class LoggerBackend(BaseBackend):
self.event_logger = logging.getLogger(name) self.event_logger = logging.getLogger(name)
def send(self, event): def send(self, event):
event_str = json.dumps(event, default=DateTimeJSONEncoder) event_str = json.dumps(event, cls=DateTimeJSONEncoder)
# TODO: remove trucation of the serialized event, either at a # TODO: remove trucation of the serialized event, either at a
# higher level during the emittion of the event, or by # higher level during the emittion of the event, or by
......
...@@ -2,6 +2,7 @@ from __future__ import absolute_import ...@@ -2,6 +2,7 @@ from __future__ import absolute_import
import json import json
import logging import logging
import datetime
from django.test import TestCase from django.test import TestCase
...@@ -26,16 +27,25 @@ class TestLoggerBackend(TestCase): ...@@ -26,16 +27,25 @@ class TestLoggerBackend(TestCase):
# Send a couple of events and check if they were recorded # Send a couple of events and check if they were recorded
# by the logger. The events are serialized to JSON. # by the logger. The events are serialized to JSON.
event = {'test': True} event = {
event_as_json = json.dumps(event) 'test': True,
'time': datetime.datetime(2012, 05, 01, 07, 27, 01, 200),
'date': datetime.date(2012, 05, 07),
}
self.backend.send(event) self.backend.send(event)
self.backend.send(event) self.backend.send(event)
self.assertEqual( saved_events = [json.loads(e) for e in self.handler.messages['info']]
self.handler.messages['info'],
[event_as_json, event_as_json] unpacked_event = {
) 'test': True,
'time': '2012-05-01T07:27:01.000200+00:00',
'date': '2012-05-07'
}
self.assertEqual(saved_events[0], unpacked_event)
self.assertEqual(saved_events[1], unpacked_event)
class MockLoggingHandler(logging.Handler): class MockLoggingHandler(logging.Handler):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment