Signed-off-by: Chris Larson <[email protected]>
---
 bin/bitbake      |   12 ++++-
 lib/bb/build.py  |    9 ++-
 lib/bb/cooker.py |    5 +-
 lib/bb/msg.py    |  136 ++++++++++++++++++++++++++++-------------------------
 4 files changed, 90 insertions(+), 72 deletions(-)

diff --git a/bin/bitbake b/bin/bitbake
index b2edcf4..4d9f551 100755
--- a/bin/bitbake
+++ b/bin/bitbake
@@ -22,7 +22,7 @@
 # with this program; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

-import sys, os, getopt, re, time, optparse, xmlrpclib
+import sys, os, getopt, re, time, optparse, xmlrpclib, logging
 sys.path.insert(0,os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])),
'lib'))
 import bb
 from bb import cooker
@@ -36,6 +36,8 @@ if sys.hexversion < 0x020600F0:
     print "Sorry, python 2.6 or later is required for this version of bitbake"
     sys.exit(1)

+logger = logging.getLogger("BitBake")
+
 #============================================================================#
 # BBOptions
 #============================================================================#
@@ -53,7 +55,7 @@ def print_exception(exc, value, tb):
     Print the exception to stderr, only showing the traceback if bitbake
     debugging is enabled.
     """
-    if not bb.msg.debug_level['default']:
+    if logger.getEffectiveLevel() > logging.DEBUG:
         tb = None

     sys.__excepthook__(exc, value, tb)
@@ -144,6 +146,12 @@ Default BBFILES are the .bb files in the current
directory.""" )
     configuration.pkgs_to_build = []
     configuration.pkgs_to_build.extend(args[1:])

+    # Set up logging to stdout in our usual format
+    console = logging.StreamHandler(sys.stdout)
+    format = logging.Formatter("%(levelname)s: %(message)s")
+    console.setFormatter(format)
+    logger.addHandler(console)
+
     cooker = bb.cooker.BBCooker(configuration)

     # Clear away any spurious environment variables. But don't wipe the
diff --git a/lib/bb/build.py b/lib/bb/build.py
index 65e8118..c9135d0 100644
--- a/lib/bb/build.py
+++ b/lib/bb/build.py
@@ -26,7 +26,7 @@
 #Based on functions from the base bb module, Copyright 2003 Holger Schurig

 from bb import data, event, mkdirhier, utils
-import bb, os, sys
+import bb, os, sys, logging

 # When we execute a python function we'd like certain things
 # in all namespaces, hence we add them to __builtins__
@@ -35,6 +35,8 @@ import bb, os, sys
 __builtins__['bb'] = bb
 __builtins__['os'] = os

+logger = logging.getLogger("BitBake")
+
 # events
 class FuncFailed(Exception):
     """
@@ -137,7 +139,7 @@ def exec_func(func, d, dirs = None):
     # Handle logfiles
     si = file('/dev/null', 'r')
     try:
-        if bb.msg.debug_level['default'] > 0 or ispython:
+        if logger.getEffectiveLevel() <= logging.DEBUG:
             so = os.popen("tee \"%s\"" % logfile, "w")
         else:
             so = file(logfile, 'w')
@@ -242,7 +244,8 @@ def exec_func_shell(func, d, runfile, logfile, flags):

     f = open(runfile, "w")
     f.write("#!/bin/sh -e\n")
-    if bb.msg.debug_level['default'] > 0: f.write("set -x\n")
+    if logger.getEffectiveLevel() <= logging.DEBUG:
+        f.write("set -x\n")
     data.emit_env(f, d)

     f.write("cd %s\n" % os.getcwd())
diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
index eacc7ac..0e044d5 100644
--- a/lib/bb/cooker.py
+++ b/lib/bb/cooker.py
@@ -73,11 +73,10 @@ class BBCooker:

         self.configuration = configuration

-        if self.configuration.verbose:
-            bb.msg.set_verbose(True)
-
         if self.configuration.debug:
             bb.msg.set_debug_level(self.configuration.debug)
+        elif self.configuration.verbose:
+            bb.msg.set_verbose(True)
         else:
             bb.msg.set_debug_level(0)

diff --git a/lib/bb/msg.py b/lib/bb/msg.py
index 7990833..641e450 100644
--- a/lib/bb/msg.py
+++ b/lib/bb/msg.py
@@ -22,11 +22,9 @@ Message handling infrastructure for bitbake
 # with this program; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

-import sys, bb
+import sys, bb, logging
 from bb import event

-debug_level = {}
-
 verbose = False

 domain = bb.utils.Enum(
@@ -43,83 +41,93 @@ domain = bb.utils.Enum(
     'TaskData',
     'Util')

+loggers = dict((msgdomain, logging.getLogger("BitBake.%s" % msgdomain))
+               for msgdomain in domain)
+logger = logging.getLogger("BitBake")

-class MsgBase(bb.event.Event):
-    """Base class for messages"""
-
-    def __init__(self, msg, d ):
-        self._message = msg
-        event.Event.__init__(self, d)
-
-class MsgDebug(MsgBase):
-    """Debug Message"""

-class MsgNote(MsgBase):
-    """Note Message"""
+#
+# Initialize our logging level names
+#
+# Perhaps we should do this in a formatter, in the application, to keep the
+# formatting there, rather than here, but this at least ensures we keep our
+# behavior consistent with previous versions.

-class MsgWarn(MsgBase):
-    """Warning Message"""
+logging.addLevelName(logging.INFO, "NOTE")
+logging.addLevelName(logging.CRITICAL, "ERROR")

-class MsgError(MsgBase):
-    """Error Message"""
+for level in xrange(logging.INFO - 1, logging.DEBUG + 1, -1):
+    logging.addLevelName(level, logging.getLevelName(logging.INFO))

-class MsgFatal(MsgBase):
-    """Fatal Message"""
+for level in xrange(logging.DEBUG - 1, 0, -1):
+    logging.addLevelName(level, logging.getLevelName(logging.DEBUG))

-class MsgPlain(MsgBase):
-    """General output"""

 #
 # Message control functions
 #

 def set_debug_level(level):
-    bb.msg.debug_level = {}
-    for domain in bb.msg.domain:
-        bb.msg.debug_level[domain] = level
-    bb.msg.debug_level['default'] = level
+    if level:
+        logger.setLevel(logging.DEBUG - (level - 1))
+    else:
+        logger.setLevel(logging.INFO)

 def set_verbose(level):
-    bb.msg.verbose = level
-
-def set_debug_domains(domains):
-    for domain in domains:
-        found = False
-        for ddomain in bb.msg.domain:
-            if domain == str(ddomain):
-                bb.msg.debug_level[ddomain] = bb.msg.debug_level[ddomain] + 1
-                found = True
-        if not found:
-            bb.msg.warn(None, "Logging domain %s is not valid,
ignoring" % domain)
+    if level:
+        logger.setLevel(logging.INFO - 1)
+    else:
+        logger.setLevel(logging.INFO)
+
+def set_debug_domains(domainargs):
+    for (domainarg, iterator) in groupby(domainargs):
+        for msgdomain in domain:
+            if str(msgdomain) == domainarg:
+                level = len(tuple(iterator))
+                if level:
+                    loggers[msgdomain].setLevel(logging.DEBUG - (level - 1))
+                break
+        else:
+            bb.msg.warn(None, "Logging domain %s is not valid,
ignoring" % domainarg)

 #
 # Message handling functions
 #

-def debug(level, domain, msg, fn = None):
-    if not domain:
-        domain = 'default'
-    if debug_level[domain] >= level:
-        bb.event.fire(MsgDebug(msg, None))
-
-def note(level, domain, msg, fn = None):
-    if not domain:
-        domain = 'default'
-    if level == 1 or verbose or debug_level[domain] >= 1:
-        bb.event.fire(MsgNote(msg, None))
-
-def warn(domain, msg, fn = None):
-    bb.event.fire(MsgWarn(msg, None))
-
-def error(domain, msg, fn = None):
-    bb.event.fire(MsgError(msg, None))
-    print 'ERROR: ' + msg
-
-def fatal(domain, msg, fn = None):
-    bb.event.fire(MsgFatal(msg, None))
-    print 'FATAL: ' + msg
-    sys.exit(1)
-
-def plain(msg, fn = None):
-    bb.event.fire(MsgPlain(msg, None))
-
+def debug(level, msgdomain, msg, fn = None):
+    level = logging.DEBUG - (level - 1)
+    if not msgdomain:
+        logger.log(level, msg)
+    else:
+        loggers[msgdomain].log(level, msg)
+
+def plain(msgdomain, fn = None):
+    if not msgdomain:
+        logger.info(msg)
+    else:
+        loggers[msgdomain].info(msg)
+
+def note(level, msgdomain, msg, fn = None):
+    level = logging.INFO - (level - 1)
+    if not msgdomain:
+        logger.log(level, msg)
+    else:
+        loggers[msgdomain].log(level, msg)
+
+def warn(msgdomain, msg, fn = None):
+    if not msgdomain:
+        logger.warn(msg)
+    else:
+        loggers[msgdomain].warn(msg)
+
+def error(msgdomain, msg, fn = None):
+    if not msgdomain:
+        logger.error(msg)
+    else:
+        loggers[msgdomain].error(msg)
+
+def fatal(msgdomain, msg, fn = None):
+    if not msgdomain:
+        logger.critical(msg)
+    else:
+        loggers[msgdomain].critical(msg)
\ No newline at end of file
-- 
1.6.4.339.g527d
_______________________________________________
Bitbake-dev mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/bitbake-dev

Reply via email to