summaryrefslogtreecommitdiffstats
path: root/bitbake
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
parente3bda7f986ca509a530b7b17417ce91e19c6c654 (diff)
downloadpoky-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')
-rw-r--r--bitbake/lib/bb/msg.py43
-rw-r--r--bitbake/lib/bb/ui/knotty.py6
2 files changed, 48 insertions, 1 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
23# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 24
25import sys 25import sys
26import copy
26import logging 27import logging
27import collections 28import collections
28from itertools import groupby 29from itertools import groupby
@@ -55,6 +56,25 @@ class BBLogFormatter(logging.Formatter):
55 CRITICAL: 'ERROR', 56 CRITICAL: 'ERROR',
56 } 57 }
57 58
59 color_enabled = False
60 BASECOLOR, BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(29,38)
61
62 COLORS = {
63 DEBUG3 : CYAN,
64 DEBUG2 : CYAN,
65 DEBUG : CYAN,
66 VERBOSE : BASECOLOR,
67 NOTE : BASECOLOR,
68 PLAIN : BASECOLOR,
69 WARNING : YELLOW,
70 ERROR : RED,
71 CRITICAL: RED,
72 }
73
74 BLD = '\033[1;%dm'
75 STD = '\033[%dm'
76 RST = '\033[0m'
77
58 def getLevelName(self, levelno): 78 def getLevelName(self, levelno):
59 try: 79 try:
60 return self.levelnames[levelno] 80 return self.levelnames[levelno]
@@ -67,6 +87,8 @@ class BBLogFormatter(logging.Formatter):
67 if record.levelno == self.PLAIN: 87 if record.levelno == self.PLAIN:
68 msg = record.getMessage() 88 msg = record.getMessage()
69 else: 89 else:
90 if self.color_enabled:
91 record = self.colorize(record)
70 msg = logging.Formatter.format(self, record) 92 msg = logging.Formatter.format(self, record)
71 93
72 if hasattr(record, 'bb_exc_info'): 94 if hasattr(record, 'bb_exc_info'):
@@ -75,6 +97,27 @@ class BBLogFormatter(logging.Formatter):
75 msg += '\n' + ''.join(formatted) 97 msg += '\n' + ''.join(formatted)
76 return msg 98 return msg
77 99
100 def colorize(self, record):
101 color = self.COLORS[record.levelno]
102 if self.color_enabled and color is not None:
103 record = copy.copy(record)
104 record.levelname = "".join([self.BLD % color, record.levelname, self.RST])
105 record.msg = "".join([self.STD % color, record.msg, self.RST])
106 return record
107
108 def enable_color(self):
109 import curses
110 try:
111 win = None
112 win = curses.initscr()
113 if curses.has_colors():
114 self.color_enabled = True
115 except:
116 pass
117 finally:
118 if win is not None:
119 curses.endwin()
120
78class BBLogFilter(object): 121class BBLogFilter(object):
79 def __init__(self, handler, level, debug_domains): 122 def __init__(self, handler, level, debug_domains):
80 self.stdlevel = level 123 self.stdlevel = level
diff --git a/bitbake/lib/bb/ui/knotty.py b/bitbake/lib/bb/ui/knotty.py
index 77ec7302a7..a63d8b120e 100644
--- a/bitbake/lib/bb/ui/knotty.py
+++ b/bitbake/lib/bb/ui/knotty.py
@@ -238,12 +238,16 @@ def main(server, eventHandler, tf = TerminalFilter):
238 helper = uihelper.BBUIHelper() 238 helper = uihelper.BBUIHelper()
239 239
240 console = logging.StreamHandler(sys.stdout) 240 console = logging.StreamHandler(sys.stdout)
241 format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s") 241 format_str = "%(levelname)s: %(message)s"
242 format = bb.msg.BBLogFormatter(format_str)
243 if interactive:
244 format.enable_color()
242 bb.msg.addDefaultlogFilter(console) 245 bb.msg.addDefaultlogFilter(console)
243 console.setFormatter(format) 246 console.setFormatter(format)
244 logger.addHandler(console) 247 logger.addHandler(console)
245 if consolelogfile: 248 if consolelogfile:
246 bb.utils.mkdirhier(os.path.dirname(consolelogfile)) 249 bb.utils.mkdirhier(os.path.dirname(consolelogfile))
250 format = bb.msg.BBLogFormatter(format_str)
247 consolelog = logging.FileHandler(consolelogfile) 251 consolelog = logging.FileHandler(consolelogfile)
248 bb.msg.addDefaultlogFilter(consolelog) 252 bb.msg.addDefaultlogFilter(consolelog)
249 consolelog.setFormatter(format) 253 consolelog.setFormatter(format)