From 774b60ac2df66199fda136610df0e947266c6bbf Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Sun, 4 Jul 2021 15:51:28 +0800 Subject: [PATCH] board_inspector: adjust logging levels The warning, info and debug logging levels are intended to be used in the following way. * Warnings are used when users are expected to be aware of a certain failure. * Info messages are used to track parsing process and major internal errors for development. * Debug messages are used to collect verbose debug logs. To align the current usage of logs to the above guidelines, this patch adjusts the logging level of the following messages: * DSDT/SSDT interpretation failures are now warnings, not information * Failures of parsing deferred AML blocks are now information, not debug messages The default log level when running `cli.py` is adjusted to WARNING as well, as INFO is primarily used for development. A new command line option `loglevel` is added to adjust the log level per user needs. v2 -> v3: * Make address collisions in ACPI namespace as an info rather than a warning. Tracked-On: #6287 Signed-off-by: Junjie Mao --- .../config_tools/board_inspector/acpiparser/aml/parser.py | 2 +- misc/config_tools/board_inspector/cli.py | 8 +++++++- misc/config_tools/board_inspector/extractors/50-acpi.py | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/misc/config_tools/board_inspector/acpiparser/aml/parser.py b/misc/config_tools/board_inspector/acpiparser/aml/parser.py index 12efd16b4..5cce3f1b4 100644 --- a/misc/config_tools/board_inspector/acpiparser/aml/parser.py +++ b/misc/config_tools/board_inspector/acpiparser/aml/parser.py @@ -431,7 +431,7 @@ class DeferredExpansion(Transformer): tree.factory = None tree.complete_parsing() except (DecodeError, DeferLater, ScopeMismatch, UndefinedSymbol) as e: - logging.debug(f"expansion of {tree.label} at {hex(tree.deferred_range[0])} failed due to: " + str(e)) + logging.info(f"expansion of {tree.label} at {hex(tree.deferred_range[0])} failed due to: " + str(e)) self.context.pop_scope() diff --git a/misc/config_tools/board_inspector/cli.py b/misc/config_tools/board_inspector/cli.py index 56fed8fb9..8142e35ed 100755 --- a/misc/config_tools/board_inspector/cli.py +++ b/misc/config_tools/board_inspector/cli.py @@ -66,12 +66,18 @@ def main(board_name, board_xml, args): sys.exit(1) if __name__ == "__main__": - logging.basicConfig(level=logging.INFO) parser = argparse.ArgumentParser() parser.add_argument("board_name", help="the name of the board that runs the ACRN hypervisor") parser.add_argument("--out", help="the name of board info file") parser.add_argument("--advanced", action="store_true", default=False, help="extract advanced information such as ACPI namespace") + parser.add_argument("--loglevel", default="warning", help="choose log level, e.g. info, warning or error") args = parser.parse_args() + try: + logging.basicConfig(level=args.loglevel.upper()) + except ValueError: + print(f"{args.loglevel} is not a valid log level") + print(f"Valid log levels (non case-sensitive): critical, error, warning, info, debug") + sys.exit(1) board_xml = args.out if args.out else f"{args.board_name}.xml" main(args.board_name, board_xml, args) diff --git a/misc/config_tools/board_inspector/extractors/50-acpi.py b/misc/config_tools/board_inspector/extractors/50-acpi.py index fea1a183a..d5d0ada59 100644 --- a/misc/config_tools/board_inspector/extractors/50-acpi.py +++ b/misc/config_tools/board_inspector/extractors/50-acpi.py @@ -151,7 +151,7 @@ def fetch_device_info(devices_node, interpreter, namepath): if isinstance(adr, int): adr = hex(adr) if len(element.xpath(f"../*[@address='{adr}']")) > 0: - logging.warning(f"{namepath} has siblings with duplicated address {adr}.") + logging.info(f"{namepath} has siblings with duplicated address {adr}.") else: element.set("address", hex(adr) if isinstance(adr, int) else adr) @@ -188,8 +188,8 @@ def extract(board_etree): try: namespace = parse_dsdt() except Exception as e: - logging.info(f"Parse ACPI DSDT/SSDT failed: {str(e)}") - logging.info(f"Will not extract information from ACPI DSDT/SSDT") + logging.warning(f"Parse ACPI DSDT/SSDT failed: {str(e)}") + logging.warning(f"Will not extract information from ACPI DSDT/SSDT") return interpreter = ConcreteInterpreter(namespace)