def republish(): # The memory logger captures both the raw messages and the # serializer. We pass them both to the global logger, so that the # expected serialization is preserved. logger = storage.logger for msg, serializer in zip(logger.messages, logger.serializers): # We copy the message here, as the cleanup function that # capture_logging installs will also try to serialize all # messages. default_logger.write(msg, serializer)
def data_received(self, data): # We write directly to the logger, as we don't want # eliot.Message to add its default fields. from eliot._output import _DEFAULT_LOGGER as logger lines = (self._eliot_buffer + data).split(b'\n') self._eliot_buffer = lines.pop(-1) for line in lines: try: message = json.loads(line) except ValueError: self._fallback(line) else: logger.write(message)
def republish(): # This is called as a cleanup function after capture_logging has # restored the global/default logger to its original state. We # can now emit messages that go to whatever global destinations # are installed. # storage.logger.serialize() seems like it would make more sense # than storage.logger.messages here. However, serialize() # explodes, seemingly as a result of double-serializing the logged # messages. I don't understand this. for msg in storage.logger.messages: default_logger.write(msg) # And now that we've re-published all of the test's messages, we # can finish the test's action. storage.action.finish()
def republish(): # This is called as a cleanup function after capture_logging has # restored the global/default logger to its original state. We # can now emit messages that go to whatever global destinations # are installed. # The memory logger captures both the raw messages and the # serializer. We pass them both to the global logger, so that the # expected serialization is preserved. logger = storage.logger for msg, serializer in zip(logger.messages, logger.serializers): default_logger.write(msg, serializer) # And now that we've re-published all of the test's messages, we # can finish the test's action. storage.action.finish()