From: Łukasz Stelmach Date: Mon, 2 Oct 2023 09:22:26 +0000 (+0200) Subject: WIP: Introduce DebugFormatter printing file/line info X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=72e9d7d63e1bbdffd83e7ba8e208fec0a2c5340b;p=platform%2Fkernel%2Fu-boot.git WIP: Introduce DebugFormatter printing file/line info Change-Id: I02cc584ea03768543b67dac71db6f6add79e5ff2 Signed-off-by: Łukasz Stelmach --- diff --git a/scripts/tizen/sd_fusing.py b/scripts/tizen/sd_fusing.py index c527e13b33..c93a81bb50 100755 --- a/scripts/tizen/sd_fusing.py +++ b/scripts/tizen/sd_fusing.py @@ -21,7 +21,15 @@ Format = False Device = "" File = "" -class ColorFormatter(logging.Formatter): +class DebugFormatter(logging.Formatter): + def format(self, record): + if record.levelno == logging.DEBUG: + record.debuginfo = "[{}:{}] ".format(os.path.basename(record.pathname), record.lineno) + else: + record.debuginfo = '' + return logging.Formatter.format(self, record) + +class ColorFormatter(DebugFormatter): _levelToColor = { logging.CRITICAL: "\x1b[35;1m", logging.ERROR: "\x1b[33;1m", @@ -33,7 +41,7 @@ class ColorFormatter(logging.Formatter): def format(self, record): record.levelcolor = self._levelToColor[record.levelno] record.msg = record.msg - return logging.Formatter.format(self, record) + return super().format(record) class ColorStreamHandler(logging.StreamHandler): def __init__(self, stream=None, format=None, datefmt=None, style='%', cformat=None): @@ -42,7 +50,7 @@ class ColorStreamHandler(logging.StreamHandler): self.formatter = ColorFormatter(cformat, datefmt, style) self.terminator = "\x1b[0m\n" else: - self.formatter = logging.Formatter(format, datefmt, style) + self.formatter = DebugFormatter(format, datefmt, style) class Partition: def __init__(self, name, size, start=None, ptype=None, fstype="raw", bootable=False): @@ -663,11 +671,11 @@ if __name__ == '__main__': print(f" {k:6} {v.long_name}") sys.exit(0) - conh = ColorStreamHandler(format='%(asctime)s %(levelname)s:%(message)s', - cformat='%(asctime)s: %(levelcolor)s%(message)s', - datefmt='%Y-%m-%dT%H:%M:%S') + conh = ColorStreamHandler(format='%(asctime)s.%(msecs)s %(debuginfo)%(levelname)-8s %(message)s', + cformat='%(asctime)s.%(msecs)s %(debuginfo)s%(levelcolor)s%(message)s', + datefmt='%Y-%m-%dT%H:%M:%S') log_handlers = [conh] - logging.basicConfig(format='%(asctime)s %(levelname)s:%(message)s', + logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s', handlers=log_handlers, level=args.log_level.upper())