diff options
author | Chris Larson <chris_larson@mentor.com> | 2010-12-09 23:38:35 -0500 |
---|---|---|
committer | Chris Larson <chris_larson@mentor.com> | 2010-12-10 09:56:15 -0500 |
commit | ee1cce6ab21ddda60a7a070d03e98ff8485a5e71 (patch) | |
tree | ab54015a15eee137416cce360dafc67131fbbf9d | |
parent | 411b808b81216473c3dbeca783ec5bc99152da26 (diff) | |
download | bitbake-ee1cce6ab21ddda60a7a070d03e98ff8485a5e71.tar.gz |
build: send logging messages to the log file for python functions
Signed-off-by: Chris Larson <chris_larson@mentor.com>
-rw-r--r-- | lib/bb/build.py | 14 | ||||
-rw-r--r-- | lib/bb/msg.py | 9 | ||||
-rw-r--r-- | lib/bb/ui/knotty.py | 12 |
3 files changed, 22 insertions, 13 deletions
diff --git a/lib/bb/build.py b/lib/bb/build.py index 163077f19..d60146173 100644 --- a/lib/bb/build.py +++ b/lib/bb/build.py @@ -29,12 +29,14 @@ import os import sys import logging import bb +import bb.msg import bb.utils import bb.process from contextlib import nested from bb import data, event, mkdirhier, utils -logger = logging.getLogger("BitBake.Build") +bblogger = logging.getLogger('BitBake') +logger = logging.getLogger('BitBake.Build') NULL = open('/dev/null', 'r') @@ -175,7 +177,7 @@ def exec_func(func, d, dirs = None): with nested(logfile, bb.utils.fileslocked(lockfiles)): try: if ispython: - exec_func_python(func, d, runfile, cwd=adir) + exec_func_python(func, d, runfile, logfile, cwd=adir) else: exec_func_shell(func, d, runfile, logfile, cwd=adir, fakeroot=fakeroot) finally: @@ -190,7 +192,8 @@ def {function}(d): {function}(d) """ -def exec_func_python(func, d, runfile, cwd=None): +logformatter = bb.msg.BBLogFormatter("%(levelname)s: %(message)s") +def exec_func_python(func, d, runfile, logfile, cwd=None): """Execute a python BB 'function'""" bbfile = d.getVar('file', True) @@ -202,6 +205,10 @@ def exec_func_python(func, d, runfile, cwd=None): if cwd: os.chdir(cwd) + handler = logging.StreamHandler(logfile) + handler.setFormatter(logformatter) + bblogger.addHandler(handler) + try: comp = utils.better_compile(code, func, bbfile) utils.better_exec(comp, {"d": d}, code, bbfile) @@ -211,6 +218,7 @@ def exec_func_python(func, d, runfile, cwd=None): raise FuncFailed(func, None) finally: + bblogger.removeHandler(handler) os.chdir(olddir) def exec_func_shell(function, d, runfile, logfile, cwd=None, fakeroot=False): diff --git a/lib/bb/msg.py b/lib/bb/msg.py index 42e20a8ec..0c1fa3bfc 100644 --- a/lib/bb/msg.py +++ b/lib/bb/msg.py @@ -30,6 +30,15 @@ import warnings import bb import bb.event +class BBLogFormatter(logging.Formatter): + """Formatter which ensures that our 'plain' messages (logging.INFO + 1) are used as is""" + + def format(self, record): + if record.levelno == logging.INFO + 1: + return record.getMessage() + else: + return logging.Formatter.format(self, record) + class Loggers(dict): def __getitem__(self, key): if key in self: diff --git a/lib/bb/ui/knotty.py b/lib/bb/ui/knotty.py index a60c1853a..b8cb2c05e 100644 --- a/lib/bb/ui/knotty.py +++ b/lib/bb/ui/knotty.py @@ -26,6 +26,7 @@ import itertools import xmlrpclib import logging import progressbar +import bb.msg from bb import ui from bb.ui import uihelper @@ -57,15 +58,6 @@ class NonInteractiveProgress(object): self.fobj.write("done.\n") self.fobj.flush() -class BBLogFormatter(logging.Formatter): - """Formatter which ensures that our 'plain' messages (logging.INFO + 1) are used as is""" - - def format(self, record): - if record.levelno == logging.INFO + 1: - return record.getMessage() - else: - return logging.Formatter.format(self, record) - def main(server, eventHandler): # Get values of variables which control our output @@ -85,7 +77,7 @@ def main(server, eventHandler): logging.addLevelName(level, logging.getLevelName(logging.DEBUG)) console = logging.StreamHandler(sys.stdout) - format = BBLogFormatter("%(levelname)s: %(message)s") + format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s") console.setFormatter(format) logger.addHandler(console) |