From ded1e31567561b367cd2a314da621c351af8e584 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 26 Jan 2016 21:30:09 +0100 Subject: [PATCH] protocols/logging: add MultilineFormatter --- artiq/protocols/logging.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/artiq/protocols/logging.py b/artiq/protocols/logging.py index 1a8d89d7c..75a92094a 100644 --- a/artiq/protocols/logging.py +++ b/artiq/protocols/logging.py @@ -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"