aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Watt <JPEWhacker@gmail.com>2020-06-05 22:15:32 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-06-06 23:12:39 +0100
commit5f363e4a9636b902229c257484ae0b479aedca65 (patch)
tree5ba8884f0457d78870d724e1c63d70a7287a967e
parent8f93d776fd6ce1a6d7094da9a9e00b5e9ee178f9 (diff)
downloadbitbake-5f363e4a9636b902229c257484ae0b479aedca65.tar.gz
bitbake: lib: Add PrefixLoggerAdapter helper
Adds a helper logger adapter to add a prefix to all log messages. This is useful to distinguish log messages between multiple instances of a object. Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--lib/bb/__init__.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/bb/__init__.py b/lib/bb/__init__.py
index cd53603a4..4e2f97b23 100644
--- a/lib/bb/__init__.py
+++ b/lib/bb/__init__.py
@@ -104,6 +104,14 @@ logger.setLevel(logging.DEBUG - 2)
mainlogger = logging.getLogger("BitBake.Main")
+class PrefixLoggerAdapter(logging.LoggerAdapter):
+ def __init__(self, prefix, logger):
+ super().__init__(logger, {})
+ self.__msg_prefix = prefix
+
+ def process(self, msg, kwargs):
+ return "%s%s" %(self.__msg_prefix, msg), kwargs
+
# This has to be imported after the setLoggerClass, as the import of bb.msg
# can result in construction of the various loggers.
import bb.msg