<div>Add bold color output to log level name and standard color output to log msg</div><div>when bitbake is run from an iteractive console.  Color output is only enabled</div><div>if the terminal supports color.</div><div>
<br></div><div>Used Jason Wessel&#39;s recommendation for transparency on verbose, note and plain.</div><div><br></div><div>Signed-off-by: Seth Bollinger &lt;<a href="mailto:seth.boll@gmail.com">seth.boll@gmail.com</a>&gt;</div>
<div>---</div><div> bitbake/lib/bb/msg.py       |   40 ++++++++++++++++++++++++++++++++++++++++</div><div> bitbake/lib/bb/ui/knotty.py |    6 +++++-</div><div> 2 files changed, 45 insertions(+), 1 deletions(-)</div><div><br>
</div><div>diff --git a/bitbake/lib/bb/msg.py b/bitbake/lib/bb/msg.py</div><div>index 9b39325..68b2ad7 100644</div><div>--- a/bitbake/lib/bb/msg.py</div><div>+++ b/bitbake/lib/bb/msg.py</div><div>@@ -55,6 +55,25 @@ class BBLogFormatter(logging.Formatter):</div>
<div>         CRITICAL: &#39;ERROR&#39;,</div><div>     }</div><div> </div><div>+    color_enabled = False</div><div>+    BASECOLOR, BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(29,38)</div><div>+</div><div>
+    COLORS = {</div><div>+        DEBUG3  : CYAN,</div><div>+        DEBUG2  : CYAN,</div><div>+        DEBUG   : CYAN,</div><div>+        VERBOSE : BASECOLOR,</div><div>+        NOTE    : BASECOLOR,</div><div>+        PLAIN   : BASECOLOR,</div>
<div>+        WARNING : YELLOW,</div><div>+        ERROR   : RED,</div><div>+        CRITICAL: RED,</div><div>+    }</div><div>+</div><div>+    BLD = &#39;\033[1;%dm&#39;</div><div>+    STD = &#39;\033[%dm&#39;</div><div>
+    RST = &#39;\033[0m&#39;</div><div>+</div><div>     def getLevelName(self, levelno):</div><div>         try:</div><div>             return self.levelnames[levelno]</div><div>@@ -67,6 +86,8 @@ class BBLogFormatter(logging.Formatter):</div>
<div>         if record.levelno == self.PLAIN:</div><div>             msg = record.getMessage()</div><div>         else:</div><div>+            if self.color_enabled:</div><div>+                self.colorize(record)</div>
<div>             msg = logging.Formatter.format(self, record)</div><div> </div><div>         if hasattr(record, &#39;bb_exc_info&#39;):</div><div>@@ -75,6 +96,25 @@ class BBLogFormatter(logging.Formatter):</div><div>             msg += &#39;\n&#39; + &#39;&#39;.join(formatted)</div>
<div>         return msg</div><div> </div><div>+    def colorize(self, record):</div><div>+        color = self.COLORS[record.levelno]</div><div>+        if self.color_enabled and color is not None:</div><div>+            record.levelname = &quot;&quot;.join([self.BLD % color, record.levelname, self.RST])</div>
<div>+            record.msg = &quot;&quot;.join([self.STD % color, record.msg, self.RST])</div><div>+</div><div>+    def enable_color(self):</div><div>+        import curses</div><div>+        try:</div><div>+            win = None</div>
<div>+            win = curses.initscr()</div><div>+            if curses.has_colors():</div><div>+                self.color_enabled = True</div><div>+        except:</div><div>+            pass</div><div>+        finally:</div>
<div>+            if win is not None:</div><div>+                curses.endwin()</div><div>+</div><div> class BBLogFilter(object):</div><div>     def __init__(self, handler, level, debug_domains):</div><div>         self.stdlevel = level</div>
<div>diff --git a/bitbake/lib/bb/ui/knotty.py b/bitbake/lib/bb/ui/knotty.py</div><div>index b99a121..d9aa973 100644</div><div>--- a/bitbake/lib/bb/ui/knotty.py</div><div>+++ b/bitbake/lib/bb/ui/knotty.py</div><div>@@ -238,12 +238,16 @@ def main(server, eventHandler, tf = TerminalFilter):</div>
<div>     helper = uihelper.BBUIHelper()</div><div> </div><div>     console = logging.StreamHandler(sys.stdout)</div><div>-    format = bb.msg.BBLogFormatter(&quot;%(levelname)s: %(message)s&quot;)</div><div>+    format_str = &quot;%(levelname)s: %(message)s&quot;</div>
<div>+    format = bb.msg.BBLogFormatter(format_str)</div><div>+    if interactive:</div><div>+        format.enable_color()</div><div>     bb.msg.addDefaultlogFilter(console)</div><div>     console.setFormatter(format)</div>
<div>     logger.addHandler(console)</div><div>     if consolelogfile:</div><div>         bb.utils.mkdirhier(os.path.dirname(consolelogfile))</div><div>+        format = bb.msg.BBLogFormatter(format_str)</div><div>         consolelog = logging.FileHandler(consolelogfile)</div>
<div>         bb.msg.addDefaultlogFilter(consolelog)</div><div>         consolelog.setFormatter(format)</div><div>-- </div><div>1.7.2.5</div><div><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Nov 14, 2012 at 7:22 AM, Richard Purdie <span dir="ltr">&lt;<a href="mailto:richard.purdie@linuxfoundation.org" target="_blank">richard.purdie@linuxfoundation.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, 2012-11-14 at 07:18 -0600, Seth Bollinger wrote:<br>
&gt; Thanks!  I&#39;ve tested this and it works on my dark color scheme (it&#39;s<br>
&gt; better actually :)).  I also tested on white and it looks fine.  If<br>
&gt; Richard is ok with this solution, I&#39;ll make the changes and submit<br>
&gt; another patch.<br>
&gt;<br>
It sounds promising, I would like to try the patch...<br>
<br>
Cheers,<br>
<br>
Richard<br>
<br>
<br>
<br>
</blockquote></div><br></div>