aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoshua Watt <JPEWhacker@gmail.com>2020-06-05 22:15:31 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-06-06 23:12:32 +0100
commit8f93d776fd6ce1a6d7094da9a9e00b5e9ee178f9 (patch)
tree3e7e72794dab83449c43d149160c764958e61666 /lib
parent5272f2489586479880ae8d046dfcdbe0963ee5bb (diff)
downloadbitbake-8f93d776fd6ce1a6d7094da9a9e00b5e9ee178f9.tar.gz
bitbake: lib: Add support for Logging Adapters
Creates a BBLoggingAdapter class that is monkey patched in place of the logginer.LoggingAdapter. The new adapter is compatible with the BBLogger class API, allowing adapters to be created for bitbake loggers. A new BBLoggerMixin class is used to reduce code duplication between the BBLogger and BBLoggerAdapter classes. Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/bb/__init__.py42
1 files changed, 38 insertions, 4 deletions
diff --git a/lib/bb/__init__.py b/lib/bb/__init__.py
index b96466e65..cd53603a4 100644
--- a/lib/bb/__init__.py
+++ b/lib/bb/__init__.py
@@ -35,12 +35,14 @@ class NullHandler(logging.Handler):
def emit(self, record):
pass
-Logger = logging.getLoggerClass()
-class BBLogger(Logger):
- def __init__(self, name):
+class BBLoggerMixin(object):
+ def __init__(self, *args, **kwargs):
+ # Does nothing to allow calling super() from derived classes
+ pass
+
+ def setup_bblogger(self, name):
if name.split(".")[0] == "BitBake":
self.debug = self.bbdebug
- Logger.__init__(self, name)
def bbdebug(self, level, msg, *args, **kwargs):
loglevel = logging.DEBUG - level + 1
@@ -60,10 +62,42 @@ class BBLogger(Logger):
def verbnote(self, msg, *args, **kwargs):
return self.log(logging.INFO + 2, msg, *args, **kwargs)
+Logger = logging.getLoggerClass()
+class BBLogger(Logger, BBLoggerMixin):
+ def __init__(self, name, *args, **kwargs):
+ self.setup_bblogger(name)
+ super().__init__(name, *args, **kwargs)
logging.raiseExceptions = False
logging.setLoggerClass(BBLogger)
+class BBLoggerAdapter(logging.LoggerAdapter, BBLoggerMixin):
+ def __init__(self, logger, *args, **kwargs):
+ self.setup_bblogger(logger.name)
+ super().__init__(logger, *args, **kwargs)
+
+ if sys.version_info < (3, 6):
+ # These properties were added in Python 3.6. Add them in older versions
+ # for compatibility
+ @property
+ def manager(self):
+ return self.logger.manager
+
+ @manager.setter
+ def manager(self, value):
+ self.logger.manager = value
+
+ @property
+ def name(self):
+ return self.logger.name
+
+ def __repr__(self):
+ logger = self.logger
+ level = getLevelName(logger.getEffectiveLevel())
+ return '<%s %s (%s)>' % (self.__class__.__name__, logger.name, level)
+
+logging.LoggerAdapter = BBLoggerAdapter
+
logger = logging.getLogger("BitBake")
logger.addHandler(NullHandler())
logger.setLevel(logging.DEBUG - 2)