Skip to content

Commit

Permalink
Include timestamp in eliot:destination_failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomprince committed Jun 16, 2015
1 parent 93e5da2 commit 51a9ee7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions eliot/_output.py
Expand Up @@ -5,6 +5,7 @@
from __future__ import unicode_literals, absolute_import

import sys
import time
import json as pyjson

from characteristic import attributes
Expand Down Expand Up @@ -143,6 +144,7 @@ class Logger(object):
can then replace a specific L{Logger} with a L{MemoryLogger}.
"""
_destinations = Destinations()
_time = time.time

def _safeUnicodeDictionary(self, dictionary):
"""
Expand Down Expand Up @@ -191,6 +193,7 @@ def write(self, dictionary, serializer=None):
self._destinations.send({
"message_type": "eliot:destination_failure",
"reason": safeunicode(exception),
"timestamp": self._time(),
"exception":
exc_type.__module__ + "." + exc_type.__name__,
"message": self._safeUnicodeDictionary(dictionary)})
Expand Down
8 changes: 7 additions & 1 deletion eliot/tests/test_output.py
Expand Up @@ -505,7 +505,8 @@ def raiser(i):
# Calling _safeUnicodeDictionary multiple times leads to
# inconsistent results due to hash ordering, so compare contents:
assertContainsFields(self, written[1],
{"message_type": "eliot:serialization_failure"})
{"message_type": "eliot:serialization_failure",
})
self.assertEqual(eval(written[1]["message"]),
dict((repr(key), repr(value)) for
(key, value) in message.items()))
Expand All @@ -517,6 +518,7 @@ def test_destinationExceptionCaught(self):
logged.
"""
logger = Logger()
logger._time = lambda: 1234.5
logger._destinations = Destinations()
dest = BadDestination()
logger._destinations.add(dest)
Expand All @@ -527,6 +529,7 @@ def test_destinationExceptionCaught(self):
self, dest[0],
{"message_type": "eliot:destination_failure",
"message": logger._safeUnicodeDictionary(message),
"timestamp": 1234.5,
"reason": "ono",
"exception": "eliot.tests.test_output.MyException"})

Expand All @@ -537,6 +540,7 @@ def test_destinationMultipleExceptionsCaught(self):
logged for each.
"""
logger = Logger()
logger._time = lambda: 1234.5
logger._destinations = Destinations()
logger._destinations.add(BadDestination())
logger._destinations.add(lambda msg: 1/0)
Expand All @@ -557,10 +561,12 @@ def test_destinationMultipleExceptionsCaught(self):
{"message_type": "eliot:destination_failure",
"message": logger._safeUnicodeDictionary(message),
"reason": "ono",
"timestamp": 1234.5,
"exception": "eliot.tests.test_output.MyException"},
{"message_type": "eliot:destination_failure",
"message": logger._safeUnicodeDictionary(message),
"reason": zero_divide,
"timestamp": 1234.5,
"exception": zero_type}])


Expand Down

0 comments on commit 51a9ee7

Please sign in to comment.