From 4855548ffbbb6b972f6b71d61d2b29e4758acdc7 Mon Sep 17 00:00:00 2001 From: Chris Larson Date: Wed, 9 Jun 2010 16:17:29 -0700 Subject: Use the python logging module under the hood for bb.msg (Bitbake rev: 47ca82397bc395b598c6b68b24cdee9e0d8a76d8) Signed-off-by: Chris Larson Signed-off-by: Richard Purdie --- bitbake/lib/bb/event.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'bitbake/lib/bb/event.py') diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py index 45458c2d63..c04ffd5ac1 100644 --- a/bitbake/lib/bb/event.py +++ b/bitbake/lib/bb/event.py @@ -24,8 +24,9 @@ BitBake build tools. import os, sys import warnings -import bb.utils import pickle +import logging +import bb.utils # This is the pid for which we should generate the event. This is set when # the runqueue forks off. @@ -56,7 +57,7 @@ bb.utils._context["Handled"] = Handled def fire_class_handlers(event, d): import bb.msg - if isinstance(event, bb.msg.MsgBase): + if isinstance(event, MsgBase): return for handler in _handlers: @@ -298,3 +299,49 @@ class DepTreeGenerated(Event): def __init__(self, depgraph): Event.__init__(self) self._depgraph = depgraph + +class MsgBase(Event): + """Base class for messages""" + + def __init__(self, msg): + self._message = msg + Event.__init__(self) + +class MsgDebug(MsgBase): + """Debug Message""" + +class MsgNote(MsgBase): + """Note Message""" + +class MsgWarn(MsgBase): + """Warning Message""" + +class MsgError(MsgBase): + """Error Message""" + +class MsgFatal(MsgBase): + """Fatal Message""" + +class MsgPlain(MsgBase): + """General output""" + +class LogHandler(logging.Handler): + """Dispatch logging messages as bitbake events""" + + messages = ( + (logging.DEBUG, MsgDebug), + (logging.INFO, MsgNote), + (logging.WARNING, MsgWarn), + (logging.ERROR, MsgError), + (logging.CRITICAL, MsgFatal), + ) + + def emit(self, record): + for level, msgclass in self.messages: + if record.levelno <= level: + msg = self.format(record) + fire(msgclass(msg), None) + if bb.event.useStdout: + print(record.levelname + ": " + record.getMessage()) + break + -- cgit v1.2.3-54-g00ecf