summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb')
-rw-r--r--bitbake/lib/bb/__init__.py42
1 files changed, 38 insertions, 4 deletions
diff --git a/bitbake/lib/bb/__init__.py b/bitbake/lib/bb/__init__.py
index b96466e654..cd53603a47 100644
--- a/bitbake/lib/bb/__init__.py
+++ b/bitbake/lib/bb/__init__.py
@@ -35,12 +35,14 @@ class NullHandler(logging.Handler):
35 def emit(self, record): 35 def emit(self, record):
36 pass 36 pass
37 37
38Logger = logging.getLoggerClass() 38class BBLoggerMixin(object):
39class BBLogger(Logger): 39 def __init__(self, *args, **kwargs):
40 def __init__(self, name): 40 # Does nothing to allow calling super() from derived classes
41 pass
42
43 def setup_bblogger(self, name):
41 if name.split(".")[0] == "BitBake": 44 if name.split(".")[0] == "BitBake":
42 self.debug = self.bbdebug 45 self.debug = self.bbdebug
43 Logger.__init__(self, name)
44 46
45 def bbdebug(self, level, msg, *args, **kwargs): 47 def bbdebug(self, level, msg, *args, **kwargs):
46 loglevel = logging.DEBUG - level + 1 48 loglevel = logging.DEBUG - level + 1
@@ -60,10 +62,42 @@ class BBLogger(Logger):
60 def verbnote(self, msg, *args, **kwargs): 62 def verbnote(self, msg, *args, **kwargs):
61 return self.log(logging.INFO + 2, msg, *args, **kwargs) 63 return self.log(logging.INFO + 2, msg, *args, **kwargs)
62 64
65Logger = logging.getLoggerClass()
66class BBLogger(Logger, BBLoggerMixin):
67 def __init__(self, name, *args, **kwargs):
68 self.setup_bblogger(name)
69 super().__init__(name, *args, **kwargs)
63 70
64logging.raiseExceptions = False 71logging.raiseExceptions = False
65logging.setLoggerClass(BBLogger) 72logging.setLoggerClass(BBLogger)
66 73
74class BBLoggerAdapter(logging.LoggerAdapter, BBLoggerMixin):
75 def __init__(self, logger, *args, **kwargs):
76 self.setup_bblogger(logger.name)
77 super().__init__(logger, *args, **kwargs)
78
79 if sys.version_info < (3, 6):
80 # These properties were added in Python 3.6. Add them in older versions
81 # for compatibility
82 @property
83 def manager(self):
84 return self.logger.manager
85
86 @manager.setter
87 def manager(self, value):
88 self.logger.manager = value
89
90 @property
91 def name(self):
92 return self.logger.name
93
94 def __repr__(self):
95 logger = self.logger
96 level = getLevelName(logger.getEffectiveLevel())
97 return '<%s %s (%s)>' % (self.__class__.__name__, logger.name, level)
98
99logging.LoggerAdapter = BBLoggerAdapter
100
67logger = logging.getLogger("BitBake") 101logger = logging.getLogger("BitBake")
68logger.addHandler(NullHandler()) 102logger.addHandler(NullHandler())
69logger.setLevel(logging.DEBUG - 2) 103logger.setLevel(logging.DEBUG - 2)