summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/msg.py
diff options
context:
space:
mode:
authorSeth Bollinger <seth.boll@gmail.com>2012-11-15 19:29:40 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-11-20 15:31:57 +0000
commitcbdc81456b68963f7ee5c72c16beaa244776898d (patch)
tree86b85afaeb93077f3b2ae2c9bc944d0504f061d8 /bitbake/lib/bb/msg.py
parente3bda7f986ca509a530b7b17417ce91e19c6c654 (diff)
downloadopenembedded-core-contrib-cbdc81456b68963f7ee5c72c16beaa244776898d.tar.gz
bitbake: knotty: Colorize knotty interactive console output
Add bold color output to log level name and standard color output to log msg when bitbake is run from an iteractive console. Color output is only enabled if the terminal supports color. Used Jason Wessel's recommendation for transparency on verbose, note and plain. (Bitbake rev: 2734240da2cc150f811129a6adf6eb4b2161b204) Signed-off-by: Seth Bollinger <seth.boll@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/msg.py')
-rw-r--r--bitbake/lib/bb/msg.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/bitbake/lib/bb/msg.py b/bitbake/lib/bb/msg.py
index 9b393252f3..007c95a4ea 100644
--- a/bitbake/lib/bb/msg.py
+++ b/bitbake/lib/bb/msg.py
@@ -23,6 +23,7 @@ Message handling infrastructure for bitbake
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import sys
+import copy
import logging
import collections
from itertools import groupby
@@ -55,6 +56,25 @@ class BBLogFormatter(logging.Formatter):
CRITICAL: 'ERROR',
}
+ color_enabled = False
+ BASECOLOR, BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(29,38)
+
+ COLORS = {
+ DEBUG3 : CYAN,
+ DEBUG2 : CYAN,
+ DEBUG : CYAN,
+ VERBOSE : BASECOLOR,
+ NOTE : BASECOLOR,
+ PLAIN : BASECOLOR,
+ WARNING : YELLOW,
+ ERROR : RED,
+ CRITICAL: RED,
+ }
+
+ BLD = '\033[1;%dm'
+ STD = '\033[%dm'
+ RST = '\033[0m'
+
def getLevelName(self, levelno):
try:
return self.levelnames[levelno]
@@ -67,6 +87,8 @@ class BBLogFormatter(logging.Formatter):
if record.levelno == self.PLAIN:
msg = record.getMessage()
else:
+ if self.color_enabled:
+ record = self.colorize(record)
msg = logging.Formatter.format(self, record)
if hasattr(record, 'bb_exc_info'):
@@ -75,6 +97,27 @@ class BBLogFormatter(logging.Formatter):
msg += '\n' + ''.join(formatted)
return msg
+ def colorize(self, record):
+ color = self.COLORS[record.levelno]
+ if self.color_enabled and color is not None:
+ record = copy.copy(record)
+ record.levelname = "".join([self.BLD % color, record.levelname, self.RST])
+ record.msg = "".join([self.STD % color, record.msg, self.RST])
+ return record
+
+ def enable_color(self):
+ import curses
+ try:
+ win = None
+ win = curses.initscr()
+ if curses.has_colors():
+ self.color_enabled = True
+ except:
+ pass
+ finally:
+ if win is not None:
+ curses.endwin()
+
class BBLogFilter(object):
def __init__(self, handler, level, debug_domains):
self.stdlevel = level