protocols/logging: add MultilineFormatter

This commit is contained in:
Sebastien Bourdeauducq 2016-01-26 21:30:09 +01:00
parent 19c5e89b4d
commit ded1e31567
1 changed files with 22 additions and 0 deletions

View File

@ -86,6 +86,28 @@ class LogParser:
stream, self.source_cb())
class MultilineFormatter(logging.Formatter):
def __init__(self):
logging.Formatter.__init__(
self, "%(levelname)s:%(name)s:%(message)s")
def format(self, record):
r = logging.Formatter.format(self, record)
linebreaks = r.count("\n")
if linebreaks:
i = r.index(":")
r = r[:i] + "<" + str(linebreaks + 1) + ">" + r[i:]
return r
def multiline_log_config(level):
root_logger = logging.getLogger()
root_logger.setLevel(level)
handler = logging.StreamHandler()
handler.setFormatter(MultilineFormatter())
root_logger.addHandler(handler)
_init_string = b"ARTIQ logging\n"