diff mbox series

[2/4] msg: add a helper to show warnings in red color

Message ID 20261013-warn-as-errors-v1-2-ab3658758ceb@bootlin.com
State New
Headers show
Series Add -W to treat warnings as errors | expand

Commit Message

Antonin Godard Oct. 13, 2026, 12:13 p.m. UTC
In preparation for the next commit, add a helper that changes the
warning color to be red, when warnings should be treated as errors. This
helps users recognizing that the -W argument was passed while still
being able to differentiate between warning and error messages (thanks
to their levelname).

Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
---
 lib/bb/msg.py | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/lib/bb/msg.py b/lib/bb/msg.py
index 4f616ff42e7..02728c44bba 100644
--- a/lib/bb/msg.py
+++ b/lib/bb/msg.py
@@ -102,6 +102,14 @@  class BBLogFormatter(logging.Formatter):
     def enable_color(self):
         self.color_enabled = True
 
+    def set_warn_color_red(self):
+        """
+        Changes the warning messages color to red. Should be
+        used when treating warnings as errors.
+        """
+        self.COLORS[self.WARNING] = self.RED
+        self.COLORS[self.WARNONCE] = self.RED
+
     def __repr__(self):
         return "%s fmt='%s' color=%s" % (self.__class__.__name__, self._fmt, "True" if self.color_enabled else "False")