scripts: tizen: sd_fusing.py: Add NOTICE log level 35/308635/2
authorŁukasz Stelmach <l.stelmach@samsung.com>
Thu, 28 Mar 2024 08:59:37 +0000 (09:59 +0100)
committerŁukasz Stelmach <l.stelmach@samsung.com>
Thu, 28 Mar 2024 10:01:05 +0000 (11:01 +0100)
Add a second normal logging level. This level should be used
for essential progress messages. Use with caution to avoid
overwhelming users with output.

Change-Id: Ib22446978af5289f647cdffbb4ccd56d56c7d086
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
scripts/tizen/sd_fusing.py

index 6937fb7..5c8b47b 100755 (executable)
@@ -22,6 +22,8 @@ Device = ""
 File = ""
 Yes = False
 
+LOGGING_NOTICE = int((logging.INFO + logging.WARNING) / 2)
+
 class DebugFormatter(logging.Formatter):
     def format(self, record):
         if record.levelno == logging.DEBUG:
@@ -35,6 +37,7 @@ class ColorFormatter(DebugFormatter):
         logging.CRITICAL: "\x1b[35;1m",
         logging.ERROR: "\x1b[33;1m",
         logging.WARNING: "\x1b[33;1m",
+        LOGGING_NOTICE: "\x1b[0m",
         logging.INFO: "\x1b[0m",
         logging.DEBUG: "\x1b[30;1m",
         logging.NOTSET: "\x1b[30;1m"
@@ -763,7 +766,7 @@ def do_fuse_file(f, name, target):
                                bufsize=(4 << 20),
                                stdin=subprocess.PIPE,
                                stdout=None, stderr=None)
-    logging.info(f"Writing {name} to {pdevice}")
+    logging.notice(f"Writing {name} to {pdevice}")
     buf = f.read(4 << 20)
     while len(buf) > 0:
         proc_dd.stdin.write(buf)
@@ -867,6 +870,18 @@ def fuse_image(args, target):
         if target.with_super:
             do_fuse_image_super(tmpd, target)
 
+def logger_notice(self, msg, *args, **kws):
+    if self.isEnabledFor(LOGGING_NOTICE):
+        self._log(LOGGING_NOTICE, msg, args, **kws)
+logging.Logger.notice = logger_notice
+
+def logging_notice(msg, *args, **kws):
+    if len(logging.root.handlers) == 0:
+        basicConfig()
+    logging.root.notice(msg, *args, **kws)
+logging.notice = logging_notice
+
+
 if __name__ == '__main__':
     parser = argparse.ArgumentParser(description="For {}, version {}".format(
         ", ".join([v.long_name for k,v in TARGETS.items()]),
@@ -878,15 +893,15 @@ if __name__ == '__main__':
     parser.add_argument("--create", action="store_true",
                         help="create the backing file and format the loopback device")
     parser.add_argument("--debug", action="store_const", const="debug",
-                        default="warning", dest="log_level",
+                        default="notice", dest="log_level",
                         help="set log level to DEBUG")
     parser.add_argument("-d", "--device",
                         help="device node or loopback backing file")
     parser.add_argument("--format", action="store_true",
                         help="create new partition table on the target device")
-    parser.add_argument("--log-level", dest="log_level", default="warning",
-                        help="Verbosity, possible values: debug, info, warning, "
-                        "error, critical (default: warning)")
+    parser.add_argument("--log-level", dest="log_level", default="notice",
+                        help="Verbosity, possible values: debug, info, notice, warning, "
+                        "error, critical (default: notice)")
     parser.add_argument("--partition-size", type=str, action="extend", dest="partition_sizes",
                         nargs='*',
                         help="override default partition size (in MiB) (used with --format), "
@@ -925,6 +940,7 @@ if __name__ == '__main__':
                 parser.error('--partition-size must follow the name=size pattern')
         args.partition_sizes = partition_sizes
 
+    logging.addLevelName(LOGGING_NOTICE, "NOTICE")
     conh = ColorStreamHandler(format='%(asctime)s.%(msecs)d %(debuginfo)s%(levelname)-8s %(message)s',
                               cformat='%(asctime)s.%(msecs)d %(debuginfo)s%(levelcolor)s%(message)s',
                               datefmt='%Y-%m-%dT%H:%M:%S')