From f6fd7ecef22509f8c64025bfa689595d7eefeb61 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 17 Oct 2015 10:21:03 +0800 Subject: [PATCH] logging: handle newlines in messages --- artiq/master/log.py | 4 +++- artiq/protocols/logging.py | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/artiq/master/log.py b/artiq/master/log.py index f8e6939ef..0211f8584 100644 --- a/artiq/master/log.py +++ b/artiq/master/log.py @@ -24,7 +24,9 @@ class LogBufferHandler(logging.Handler): def emit(self, record): message = self.format(record) - self.log_buffer.log(record.levelno, record.source, record.created, message) + for part in message.split("\n"): + self.log_buffer.log(record.levelno, record.source, record.created, + part) def log_worker(rid, message): diff --git a/artiq/protocols/logging.py b/artiq/protocols/logging.py index 6333942da..f65212550 100644 --- a/artiq/protocols/logging.py +++ b/artiq/protocols/logging.py @@ -101,16 +101,18 @@ class LogForwarder(logging.Handler, TaskObject): self.host = host self.port = port self.setFormatter(logging.Formatter( - "%(source)s:%(levelno)d:%(name)s:%(message)s")) + "%(name)s:%(message)s")) self._queue = asyncio.Queue(queue_size) self.reconnect_timer = reconnect_timer def emit(self, record): message = self.format(record) - try: - self._queue.put_nowait(message) - except asyncio.QueueFull: - pass + for part in message.split("\n"): + part = "{}:{}:{}".format(record.source, record.levelno, part) + try: + self._queue.put_nowait(part) + except asyncio.QueueFull: + break async def _do(self): while True: