summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/msg.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/msg.py')
-rw-r--r--bitbake/lib/bb/msg.py89
1 files changed, 48 insertions, 41 deletions
diff --git a/bitbake/lib/bb/msg.py b/bitbake/lib/bb/msg.py
index 05645739d4..582165dd08 100644
--- a/bitbake/lib/bb/msg.py
+++ b/bitbake/lib/bb/msg.py
@@ -229,6 +229,53 @@ def has_console_handler(logger):
229 return True 229 return True
230 return False 230 return False
231 231
232def mergeLoggingConfig(logconfig, userconfig):
233 logconfig = copy.deepcopy(logconfig)
234 userconfig = copy.deepcopy(userconfig)
235
236 # Merge config with the default config
237 if userconfig.get('version') != logconfig['version']:
238 raise BaseException("Bad user configuration version. Expected %r, got %r" % (logconfig['version'], userconfig.get('version')))
239
240 # Set some defaults to make merging easier
241 userconfig.setdefault("loggers", {})
242
243 # If a handler, formatter, or filter is defined in the user
244 # config, it will replace an existing one in the default config
245 for k in ("handlers", "formatters", "filters"):
246 logconfig.setdefault(k, {}).update(userconfig.get(k, {}))
247
248 seen_loggers = set()
249 for name, l in logconfig["loggers"].items():
250 # If the merge option is set, merge the handlers and
251 # filters. Otherwise, if it is False, this logger won't get
252 # add to the set of seen loggers and will replace the
253 # existing one
254 if l.get('bitbake_merge', True):
255 ulogger = userconfig["loggers"].setdefault(name, {})
256 ulogger.setdefault("handlers", [])
257 ulogger.setdefault("filters", [])
258
259 # Merge lists
260 l.setdefault("handlers", []).extend(ulogger["handlers"])
261 l.setdefault("filters", []).extend(ulogger["filters"])
262
263 # Replace other properties if present
264 if "level" in ulogger:
265 l["level"] = ulogger["level"]
266
267 if "propagate" in ulogger:
268 l["propagate"] = ulogger["propagate"]
269
270 seen_loggers.add(name)
271
272 # Add all loggers present in the user config, but not any that
273 # have already been processed
274 for name in set(userconfig["loggers"].keys()) - seen_loggers:
275 logconfig["loggers"][name] = userconfig["loggers"][name]
276
277 return logconfig
278
232def setLoggingConfig(defaultconfig, userconfigfile=None): 279def setLoggingConfig(defaultconfig, userconfigfile=None):
233 logconfig = copy.deepcopy(defaultconfig) 280 logconfig = copy.deepcopy(defaultconfig)
234 281
@@ -244,47 +291,7 @@ def setLoggingConfig(defaultconfig, userconfigfile=None):
244 raise BaseException("Unrecognized file format: %s" % userconfigfile) 291 raise BaseException("Unrecognized file format: %s" % userconfigfile)
245 292
246 if userconfig.get('bitbake_merge', True): 293 if userconfig.get('bitbake_merge', True):
247 # Merge config with the default config 294 logconfig = mergeLoggingConfig(logconfig, userconfig)
248 if userconfig.get('version') != logconfig['version']:
249 raise BaseException("Bad user configuration version. Expected %r, got %r" % (logconfig['version'], userconfig.get('version')))
250
251 # Set some defaults to make merging easier
252 userconfig.setdefault("loggers", {})
253
254 # If a handler, formatter, or filter is defined in the user
255 # config, it will replace an existing one in the default config
256 for k in ("handlers", "formatters", "filters"):
257 logconfig.setdefault(k, {}).update(userconfig.get(k, {}))
258
259 seen_loggers = set()
260 for name, l in logconfig["loggers"].items():
261 # If the merge option is set, merge the handlers and
262 # filters. Otherwise, if it is False, this logger won't get
263 # add to the set of seen loggers and will replace the
264 # existing one
265 if l.get('bitbake_merge', True):
266 ulogger = userconfig["loggers"].setdefault(name, {})
267 ulogger.setdefault("handlers", [])
268 ulogger.setdefault("filters", [])
269
270 # Merge lists
271 l.setdefault("handlers", []).extend(ulogger["handlers"])
272 l.setdefault("filters", []).extend(ulogger["filters"])
273
274 # Replace other properties if present
275 if "level" in ulogger:
276 l["level"] = ulogger["level"]
277
278 if "propagate" in ulogger:
279 l["propagate"] = ulogger["propagate"]
280
281 seen_loggers.add(name)
282
283 # Add all loggers present in the user config, but not any that
284 # have already been processed
285 for name in set(userconfig["loggers"].keys()) - seen_loggers:
286 logconfig["loggers"][name] = userconfig["loggers"][name]
287
288 else: 295 else:
289 # Replace the entire default config 296 # Replace the entire default config
290 logconfig = userconfig 297 logconfig = userconfig