forked from M-Labs/artiq
logging: handle newlines in messages
This commit is contained in:
parent
6c856025cc
commit
f6fd7ecef2
|
@ -24,7 +24,9 @@ class LogBufferHandler(logging.Handler):
|
||||||
|
|
||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
message = self.format(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):
|
def log_worker(rid, message):
|
||||||
|
|
|
@ -101,16 +101,18 @@ class LogForwarder(logging.Handler, TaskObject):
|
||||||
self.host = host
|
self.host = host
|
||||||
self.port = port
|
self.port = port
|
||||||
self.setFormatter(logging.Formatter(
|
self.setFormatter(logging.Formatter(
|
||||||
"%(source)s:%(levelno)d:%(name)s:%(message)s"))
|
"%(name)s:%(message)s"))
|
||||||
self._queue = asyncio.Queue(queue_size)
|
self._queue = asyncio.Queue(queue_size)
|
||||||
self.reconnect_timer = reconnect_timer
|
self.reconnect_timer = reconnect_timer
|
||||||
|
|
||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
message = self.format(record)
|
message = self.format(record)
|
||||||
try:
|
for part in message.split("\n"):
|
||||||
self._queue.put_nowait(message)
|
part = "{}:{}:{}".format(record.source, record.levelno, part)
|
||||||
except asyncio.QueueFull:
|
try:
|
||||||
pass
|
self._queue.put_nowait(part)
|
||||||
|
except asyncio.QueueFull:
|
||||||
|
break
|
||||||
|
|
||||||
async def _do(self):
|
async def _do(self):
|
||||||
while True:
|
while True:
|
||||||
|
|
Loading…
Reference in New Issue