summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/ui/knotty.py
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2010-06-10 08:05:52 -0700
committerRichard Purdie <rpurdie@linux.intel.com>2011-01-04 14:46:33 +0000
commitd3a45c7d41a88d79389fc40eb68816e4939fb6f9 (patch)
tree443e2828e6d5e86f59b8b238607ef38646c1f23f /bitbake/lib/bb/ui/knotty.py
parent4855548ffbbb6b972f6b71d61d2b29e4758acdc7 (diff)
downloadpoky-d3a45c7d41a88d79389fc40eb68816e4939fb6f9.tar.gz
Use logging in the knotty ui, and pass the log record across directly
This kills firing of Msg* events in favor of just passing along LogRecord objects. These objects hold more than just level and message, but can also have exception information, so the UI can decide what to do with that. As an aside, when using the 'none' server, this results in the log messages in the server being displayed directly via the logging module and the UI's handler, rather than going through the server's event queue. As a result of doing it this way, we have to override the event handlers of the base logger when spawning a worker process, to ensure they log via events rather than directly. (Bitbake rev: c23c015cf8af1868faf293b19b80a5faf7e736a5) Signed-off-by: Chris Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib/bb/ui/knotty.py')
-rw-r--r--bitbake/lib/bb/ui/knotty.py72
1 files changed, 41 insertions, 31 deletions
diff --git a/bitbake/lib/bb/ui/knotty.py b/bitbake/lib/bb/ui/knotty.py
index 9162c79f6a..177a12609c 100644
--- a/bitbake/lib/bb/ui/knotty.py
+++ b/bitbake/lib/bb/ui/knotty.py
@@ -24,12 +24,22 @@ import os
24import sys 24import sys
25import itertools 25import itertools
26import xmlrpclib 26import xmlrpclib
27import logging
27from bb import ui 28from bb import ui
28from bb.ui import uihelper 29from bb.ui import uihelper
29 30
30 31logger = logging.getLogger("BitBake")
31parsespin = itertools.cycle( r'|/-\\' ) 32parsespin = itertools.cycle( r'|/-\\' )
32 33
34class BBLogFormatter(logging.Formatter):
35 """Formatter which ensures that our 'plain' messages (logging.INFO + 1) are used as is"""
36
37 def format(self, record):
38 if record.levelno == logging.INFO + 1:
39 return record.getMessage()
40 else:
41 return logging.Formatter.format(self, record)
42
33def init(server, eventHandler): 43def init(server, eventHandler):
34 44
35 # Get values of variables which control our output 45 # Get values of variables which control our output
@@ -38,9 +48,23 @@ def init(server, eventHandler):
38 48
39 helper = uihelper.BBUIHelper() 49 helper = uihelper.BBUIHelper()
40 50
51 # Set up logging to stdout in our usual format
52 logging.addLevelName(logging.INFO, "NOTE")
53 logging.addLevelName(logging.CRITICAL, "FATAL")
54
55 for level in xrange(logging.INFO - 1, logging.DEBUG + 1, -1):
56 logging.addLevelName(level, logging.getLevelName(logging.INFO))
57
58 for level in xrange(logging.DEBUG - 1, 0, -1):
59 logging.addLevelName(level, logging.getLevelName(logging.DEBUG))
60
61 console = logging.StreamHandler(sys.stdout)
62 format = BBLogFormatter("%(levelname)s: %(message)s")
63 console.setFormatter(format)
64 logger.addHandler(console)
65
41 try: 66 try:
42 cmdline = server.runCommand(["getCmdLineAction"]) 67 cmdline = server.runCommand(["getCmdLineAction"])
43 #print cmdline
44 if not cmdline: 68 if not cmdline:
45 return 1 69 return 1
46 ret = server.runCommand(cmdline) 70 ret = server.runCommand(cmdline)
@@ -58,7 +82,6 @@ def init(server, eventHandler):
58 event = eventHandler.waitEvent(0.25) 82 event = eventHandler.waitEvent(0.25)
59 if event is None: 83 if event is None:
60 continue 84 continue
61 #print event
62 helper.eventHandler(event) 85 helper.eventHandler(event)
63 if isinstance(event, bb.runqueue.runQueueExitWait): 86 if isinstance(event, bb.runqueue.runQueueExitWait):
64 if not shutdown: 87 if not shutdown:
@@ -72,26 +95,13 @@ def init(server, eventHandler):
72 print("%s: %s (pid %s)" % (tasknum, activetasks[task]["title"], task)) 95 print("%s: %s (pid %s)" % (tasknum, activetasks[task]["title"], task))
73 tasknum = tasknum + 1 96 tasknum = tasknum + 1
74 97
75 if isinstance(event, bb.event.MsgPlain): 98 if isinstance(event, logging.LogRecord):
76 print(event._message) 99 if event.levelno is logging.CRITICAL or event.levelno is logging.ERROR:
77 continue 100 return_value = 1
78 if isinstance(event, bb.event.MsgDebug): 101 if isinstance(event, logging.LogRecord):
79 print('DEBUG: ' + event._message) 102 logger.handle(event)
80 continue
81 if isinstance(event, bb.event.MsgNote):
82 print('NOTE: ' + event._message)
83 continue
84 if isinstance(event, bb.event.MsgWarn):
85 print('WARNING: ' + event._message)
86 continue
87 if isinstance(event, bb.event.MsgError):
88 return_value = 1
89 print('ERROR: ' + event._message)
90 continue
91 if isinstance(event, bb.event.MsgFatal):
92 return_value = 1
93 print('FATAL: ' + event._message)
94 continue 103 continue
104
95 if isinstance(event, bb.build.TaskFailed): 105 if isinstance(event, bb.build.TaskFailed):
96 return_value = 1 106 return_value = 1
97 logfile = event.logfile 107 logfile = event.logfile
@@ -117,7 +127,7 @@ def init(server, eventHandler):
117 for line in lines: 127 for line in lines:
118 print(line) 128 print(line)
119 if isinstance(event, bb.build.TaskBase): 129 if isinstance(event, bb.build.TaskBase):
120 print("NOTE: %s" % event._message) 130 logger.info(event._message)
121 continue 131 continue
122 if isinstance(event, bb.event.ParseProgress): 132 if isinstance(event, bb.event.ParseProgress):
123 x = event.sofar 133 x = event.sofar
@@ -144,15 +154,15 @@ def init(server, eventHandler):
144 continue 154 continue
145 if isinstance(event, bb.command.CookerCommandFailed): 155 if isinstance(event, bb.command.CookerCommandFailed):
146 return_value = 1 156 return_value = 1
147 print("Command execution failed: %s" % event.error) 157 logger.error("Command execution failed: %s" % event.error)
148 break 158 break
149 if isinstance(event, bb.cooker.CookerExit): 159 if isinstance(event, bb.cooker.CookerExit):
150 break 160 break
151 if isinstance(event, bb.event.MultipleProviders): 161 if isinstance(event, bb.event.MultipleProviders):
152 print("NOTE: multiple providers are available for %s%s (%s)" % (event._is_runtime and "runtime " or "", 162 logger.info("multiple providers are available for %s%s (%s)", event._is_runtime and "runtime " or "",
153 event._item, 163 event._item,
154 ", ".join(event._candidates))) 164 ", ".join(event._candidates))
155 print("NOTE: consider defining a PREFERRED_PROVIDER entry to match %s" % event._item) 165 logger.info("consider defining a PREFERRED_PROVIDER entry to match %s", event._item)
156 continue 166 continue
157 if isinstance(event, bb.event.NoProvider): 167 if isinstance(event, bb.event.NoProvider):
158 if event._runtime: 168 if event._runtime:
@@ -161,9 +171,9 @@ def init(server, eventHandler):
161 r = "" 171 r = ""
162 172
163 if event._dependees: 173 if event._dependees:
164 print("ERROR: Nothing %sPROVIDES '%s' (but %s %sDEPENDS on or otherwise requires it)" % (r, event._item, ", ".join(event._dependees), r)) 174 logger.error("Nothing %sPROVIDES '%s' (but %s %sDEPENDS on or otherwise requires it)", r, event._item, ", ".join(event._dependees), r)
165 else: 175 else:
166 print("ERROR: Nothing %sPROVIDES '%s'" % (r, event._item)) 176 logger.error("Nothing %sPROVIDES '%s'", r, event._item)
167 continue 177 continue
168 178
169 # ignore 179 # ignore
@@ -175,7 +185,7 @@ def init(server, eventHandler):
175 bb.runqueue.runQueueExitWait)): 185 bb.runqueue.runQueueExitWait)):
176 continue 186 continue
177 187
178 print("Unknown Event: %s" % event) 188 logger.error("Unknown event: %s", event)
179 189
180 except KeyboardInterrupt: 190 except KeyboardInterrupt:
181 if shutdown == 2: 191 if shutdown == 2: