diff options
author | Joshua Watt <JPEWhacker@gmail.com> | 2020-03-09 11:33:48 -0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-03-13 11:29:23 +0000 |
commit | 1c9874b9f3a7e3a748279c13e453d09827aab39c (patch) | |
tree | 775d8051a5ee2c3bbe164ca9fb669057cddd2f9b /bitbake/lib | |
parent | 300fd2a659a50e84b4fff0c76398cbbd1d62f5d1 (diff) | |
download | poky-1c9874b9f3a7e3a748279c13e453d09827aab39c.tar.gz |
bitbake: knotty: Setup logs with config helper
Sets up logging in knotty to use python's structured logging config and
the bb.msg.setLoggingConfig() helper to setup logging. This allows the
user to specify additional logging mechanism in a config file with
BB_LOGCONFIG
(Bitbake rev: 646a68a49364b50a42168b4b16308f7217eec0dc)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r-- | bitbake/lib/bb/ui/knotty.py | 134 |
1 files changed, 96 insertions, 38 deletions
diff --git a/bitbake/lib/bb/ui/knotty.py b/bitbake/lib/bb/ui/knotty.py index d5dce7172a..386f27876d 100644 --- a/bitbake/lib/bb/ui/knotty.py +++ b/bitbake/lib/bb/ui/knotty.py | |||
@@ -370,7 +370,11 @@ def _log_settings_from_server(server, observe_only): | |||
370 | if error: | 370 | if error: |
371 | logger.error("Unable to get the value of BB_CONSOLELOG variable: %s" % error) | 371 | logger.error("Unable to get the value of BB_CONSOLELOG variable: %s" % error) |
372 | raise BaseException(error) | 372 | raise BaseException(error) |
373 | return includelogs, loglines, consolelogfile | 373 | logconfigfile, error = server.runCommand([cmd, "BB_LOGCONFIG"]) |
374 | if error: | ||
375 | logger.error("Unable to get the value of BB_LOGCONFIG variable: %s" % error) | ||
376 | raise BaseException(error) | ||
377 | return includelogs, loglines, consolelogfile, logconfigfile | ||
374 | 378 | ||
375 | _evt_list = [ "bb.runqueue.runQueueExitWait", "bb.event.LogExecTTY", "logging.LogRecord", | 379 | _evt_list = [ "bb.runqueue.runQueueExitWait", "bb.event.LogExecTTY", "logging.LogRecord", |
376 | "bb.build.TaskFailed", "bb.build.TaskBase", "bb.event.ParseStarted", | 380 | "bb.build.TaskFailed", "bb.build.TaskBase", "bb.event.ParseStarted", |
@@ -387,7 +391,87 @@ def main(server, eventHandler, params, tf = TerminalFilter): | |||
387 | if not params.observe_only: | 391 | if not params.observe_only: |
388 | params.updateToServer(server, os.environ.copy()) | 392 | params.updateToServer(server, os.environ.copy()) |
389 | 393 | ||
390 | includelogs, loglines, consolelogfile = _log_settings_from_server(server, params.observe_only) | 394 | includelogs, loglines, consolelogfile, logconfigfile = _log_settings_from_server(server, params.observe_only) |
395 | |||
396 | loglevel, _ = bb.msg.constructLogOptions() | ||
397 | |||
398 | if params.options.quiet == 0: | ||
399 | console_loglevel = loglevel | ||
400 | elif params.options.quiet > 2: | ||
401 | console_loglevel = bb.msg.BBLogFormatter.ERROR | ||
402 | else: | ||
403 | console_loglevel = bb.msg.BBLogFormatter.WARNING | ||
404 | |||
405 | logconfig = { | ||
406 | "version": 1, | ||
407 | "handlers": { | ||
408 | "BitBake.console": { | ||
409 | "class": "logging.StreamHandler", | ||
410 | "formatter": "BitBake.consoleFormatter", | ||
411 | "level": console_loglevel, | ||
412 | "stream": "ext://sys.stdout", | ||
413 | "filters": ["BitBake.stdoutFilter"], | ||
414 | }, | ||
415 | "BitBake.errconsole": { | ||
416 | "class": "logging.StreamHandler", | ||
417 | "formatter": "BitBake.consoleFormatter", | ||
418 | "level": loglevel, | ||
419 | "stream": "ext://sys.stderr", | ||
420 | "filters": ["BitBake.stderrFilter"], | ||
421 | }, | ||
422 | }, | ||
423 | "formatters": { | ||
424 | # This format instance will get color output enabled by the | ||
425 | # terminal | ||
426 | "BitBake.consoleFormatter" : { | ||
427 | "()": "bb.msg.BBLogFormatter", | ||
428 | "format": "%(levelname)s: %(message)s" | ||
429 | }, | ||
430 | # The file log requires a separate instance so that it doesn't get | ||
431 | # color enabled | ||
432 | "BitBake.logfileFormatter": { | ||
433 | "()": "bb.msg.BBLogFormatter", | ||
434 | "format": "%(levelname)s: %(message)s" | ||
435 | } | ||
436 | }, | ||
437 | "filters": { | ||
438 | "BitBake.stdoutFilter": { | ||
439 | "()": "bb.msg.LogFilterLTLevel", | ||
440 | "level": "ERROR" | ||
441 | }, | ||
442 | "BitBake.stderrFilter": { | ||
443 | "()": "bb.msg.LogFilterGEQLevel", | ||
444 | "level": "ERROR" | ||
445 | } | ||
446 | }, | ||
447 | "loggers": { | ||
448 | "BitBake": { | ||
449 | "level": loglevel, | ||
450 | "handlers": ["BitBake.console", "BitBake.errconsole"], | ||
451 | } | ||
452 | }, | ||
453 | "disable_existing_loggers": False | ||
454 | } | ||
455 | |||
456 | # Enable the console log file if enabled | ||
457 | if consolelogfile and not params.options.show_environment and not params.options.show_versions: | ||
458 | logconfig["handlers"]["BitBake.consolelog"] ={ | ||
459 | "class": "logging.FileHandler", | ||
460 | "formatter": "BitBake.logfileFormatter", | ||
461 | "level": "INFO", | ||
462 | "filename": consolelogfile, | ||
463 | } | ||
464 | logconfig["loggers"]["BitBake"]["handlers"].append("BitBake.consolelog") | ||
465 | |||
466 | bb.utils.mkdirhier(os.path.dirname(consolelogfile)) | ||
467 | loglink = os.path.join(os.path.dirname(consolelogfile), 'console-latest.log') | ||
468 | bb.utils.remove(loglink) | ||
469 | try: | ||
470 | os.symlink(os.path.basename(consolelogfile), loglink) | ||
471 | except OSError: | ||
472 | pass | ||
473 | |||
474 | bb.msg.setLoggingConfig(logconfig, logconfigfile) | ||
391 | 475 | ||
392 | if sys.stdin.isatty() and sys.stdout.isatty(): | 476 | if sys.stdin.isatty() and sys.stdout.isatty(): |
393 | log_exec_tty = True | 477 | log_exec_tty = True |
@@ -396,23 +480,16 @@ def main(server, eventHandler, params, tf = TerminalFilter): | |||
396 | 480 | ||
397 | helper = uihelper.BBUIHelper() | 481 | helper = uihelper.BBUIHelper() |
398 | 482 | ||
399 | console = logging.StreamHandler(sys.stdout) | 483 | # Look for the specially designated handlers which need to be passed to the |
400 | errconsole = logging.StreamHandler(sys.stderr) | 484 | # terminal handler |
401 | format_str = "%(levelname)s: %(message)s" | 485 | console = None |
402 | format = bb.msg.BBLogFormatter(format_str) | 486 | errconsole = None |
403 | if params.options.quiet == 0: | 487 | for h in logger.handlers: |
404 | forcelevel = None | 488 | name = getattr(h, '_name', None) |
405 | elif params.options.quiet > 2: | 489 | if name == 'BitBake.console': |
406 | forcelevel = bb.msg.BBLogFormatter.ERROR | 490 | console = h |
407 | else: | 491 | elif name == 'BitBake.errconsole': |
408 | forcelevel = bb.msg.BBLogFormatter.WARNING | 492 | errconsole = h |
409 | bb.msg.addDefaultlogFilter(console, bb.msg.BBLogFilterStdOut, forcelevel) | ||
410 | bb.msg.addDefaultlogFilter(errconsole, bb.msg.BBLogFilterStdErr) | ||
411 | console.setFormatter(format) | ||
412 | errconsole.setFormatter(format) | ||
413 | if not bb.msg.has_console_handler(logger): | ||
414 | logger.addHandler(console) | ||
415 | logger.addHandler(errconsole) | ||
416 | 493 | ||
417 | bb.utils.set_process_name("KnottyUI") | 494 | bb.utils.set_process_name("KnottyUI") |
418 | 495 | ||
@@ -420,21 +497,6 @@ def main(server, eventHandler, params, tf = TerminalFilter): | |||
420 | server.terminateServer() | 497 | server.terminateServer() |
421 | return | 498 | return |
422 | 499 | ||
423 | consolelog = None | ||
424 | if consolelogfile and not params.options.show_environment and not params.options.show_versions: | ||
425 | bb.utils.mkdirhier(os.path.dirname(consolelogfile)) | ||
426 | conlogformat = bb.msg.BBLogFormatter(format_str) | ||
427 | consolelog = logging.FileHandler(consolelogfile) | ||
428 | bb.msg.addDefaultlogFilter(consolelog) | ||
429 | consolelog.setFormatter(conlogformat) | ||
430 | logger.addHandler(consolelog) | ||
431 | loglink = os.path.join(os.path.dirname(consolelogfile), 'console-latest.log') | ||
432 | bb.utils.remove(loglink) | ||
433 | try: | ||
434 | os.symlink(os.path.basename(consolelogfile), loglink) | ||
435 | except OSError: | ||
436 | pass | ||
437 | |||
438 | llevel, debug_domains = bb.msg.constructLogOptions() | 500 | llevel, debug_domains = bb.msg.constructLogOptions() |
439 | server.runCommand(["setEventMask", server.getEventHandle(), llevel, debug_domains, _evt_list]) | 501 | server.runCommand(["setEventMask", server.getEventHandle(), llevel, debug_domains, _evt_list]) |
440 | 502 | ||
@@ -761,8 +823,4 @@ def main(server, eventHandler, params, tf = TerminalFilter): | |||
761 | if e.errno == errno.EPIPE: | 823 | if e.errno == errno.EPIPE: |
762 | pass | 824 | pass |
763 | 825 | ||
764 | if consolelog: | ||
765 | logger.removeHandler(consolelog) | ||
766 | consolelog.close() | ||
767 | |||
768 | return return_value | 826 | return return_value |