From 273ac8531d280e9e91cceeadfdf4afb2bc014809 Mon Sep 17 00:00:00 2001 From: Jennifer Power Date: Fri, 22 Mar 2024 17:56:21 -0400 Subject: [PATCH 1/3] chore: removes detailed formatting from info level logs Signed-off-by: Jennifer Power --- trestlebot/entrypoints/log.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/trestlebot/entrypoints/log.py b/trestlebot/entrypoints/log.py index 3503c1ba..178eee6c 100644 --- a/trestlebot/entrypoints/log.py +++ b/trestlebot/entrypoints/log.py @@ -31,17 +31,23 @@ def configure_logger(level: int = logging.INFO) -> None: _logger.setLevel(level=level) # Create a StreamHandler to send non-error logs to stdout - stdout_handler = logging.StreamHandler(sys.stdout) - stdout_handler.setLevel(logging.DEBUG) + stdout_info_handler = logging.StreamHandler(sys.stdout) + stdout_info_handler.setLevel(logging.INFO) + + stdout_debug_handler = logging.StreamHandler(sys.stdout) + stdout_debug_handler.setLevel(logging.DEBUG) # Create a StreamHandler to send error logs to stderr stderr_handler = logging.StreamHandler(sys.stderr) stderr_handler.setLevel(logging.ERROR) # Create a formatter and set it on both handlers - log_formatter = logging.Formatter("%(name)s:%(lineno)d %(levelname)s: %(message)s") - stdout_handler.setFormatter(log_formatter) - stderr_handler.setFormatter(log_formatter) - - _logger.addHandler(stdout_handler) + detailed_formatter = logging.Formatter( + "%(name)s:%(lineno)d %(levelname)s: %(message)s" + ) + stdout_debug_handler.setFormatter(detailed_formatter) + stderr_handler.setFormatter(detailed_formatter) + + _logger.addHandler(stdout_debug_handler) + _logger.addHandler(stdout_info_handler) _logger.addHandler(stderr_handler) From ff405f62ac3cf503fb413de8f46ed2ab9b848f4c Mon Sep 17 00:00:00 2001 From: Jennifer Power Date: Fri, 22 Mar 2024 18:14:01 -0400 Subject: [PATCH 2/3] fix: removes duplicated log messages Signed-off-by: Jennifer Power --- trestlebot/entrypoints/log.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/trestlebot/entrypoints/log.py b/trestlebot/entrypoints/log.py index 178eee6c..e2995b24 100644 --- a/trestlebot/entrypoints/log.py +++ b/trestlebot/entrypoints/log.py @@ -33,13 +33,15 @@ def configure_logger(level: int = logging.INFO) -> None: # Create a StreamHandler to send non-error logs to stdout stdout_info_handler = logging.StreamHandler(sys.stdout) stdout_info_handler.setLevel(logging.INFO) + stdout_info_handler.addFilter(log.SpecificLevelFilter(logging.INFO)) stdout_debug_handler = logging.StreamHandler(sys.stdout) stdout_debug_handler.setLevel(logging.DEBUG) + stdout_debug_handler.addFilter(log.SpecificLevelFilter(logging.DEBUG)) # Create a StreamHandler to send error logs to stderr stderr_handler = logging.StreamHandler(sys.stderr) - stderr_handler.setLevel(logging.ERROR) + stderr_handler.setLevel(logging.WARNING) # Create a formatter and set it on both handlers detailed_formatter = logging.Formatter( From 0d840f3d61320b3fdea32dbd7e2093d9335963e3 Mon Sep 17 00:00:00 2001 From: Jennifer Power Date: Fri, 22 Mar 2024 20:21:39 -0400 Subject: [PATCH 3/3] chore: adds additional logging messages around model processing Signed-off-by: Jennifer Power --- trestlebot/tasks/assemble_task.py | 5 +++++ trestlebot/tasks/regenerate_task.py | 5 +++++ trestlebot/tasks/rule_transform_task.py | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/trestlebot/tasks/assemble_task.py b/trestlebot/tasks/assemble_task.py index fca1f915..1c755837 100644 --- a/trestlebot/tasks/assemble_task.py +++ b/trestlebot/tasks/assemble_task.py @@ -4,6 +4,7 @@ """Trestle Bot Assembly Tasks""" +import logging import os import pathlib from typing import Optional @@ -16,6 +17,9 @@ from trestlebot.tasks.base_task import ModelFilter, TaskBase, TaskException +logger = logging.getLogger(__name__) + + class AssembleTask(TaskBase): """ Assemble Markdown into OSCAL content @@ -62,6 +66,7 @@ def _assemble(self) -> int: for model in self.iterate_models(pathlib.Path(search_path)): # Construct model path from markdown path. AuthoredObject already has # the working dir data as part of object construction. + logger.info(f"Assembling model {model}") model_base_name = os.path.basename(model) model_path = os.path.join(self._markdown_dir, model_base_name) try: diff --git a/trestlebot/tasks/regenerate_task.py b/trestlebot/tasks/regenerate_task.py index 8b05cb36..ed9ab836 100644 --- a/trestlebot/tasks/regenerate_task.py +++ b/trestlebot/tasks/regenerate_task.py @@ -4,6 +4,7 @@ """Trestle Bot Regenerate Tasks""" +import logging import os import pathlib from typing import Optional @@ -17,6 +18,9 @@ from trestlebot.tasks.base_task import ModelFilter, TaskBase, TaskException +logger = logging.getLogger(__name__) + + class RegenerateTask(TaskBase): """ Regenerate Trestle Markdown from OSCAL JSON content changes @@ -58,6 +62,7 @@ def _regenerate(self) -> int: search_path = os.path.join(self.working_dir, model_dir) for model in self.iterate_models(pathlib.Path(search_path)): + logger.info(f"Regenerating model {model}") model_base_name = os.path.basename(model) model_path = os.path.join(model_dir, model_base_name) diff --git a/trestlebot/tasks/rule_transform_task.py b/trestlebot/tasks/rule_transform_task.py index a69663a6..3f25d372 100644 --- a/trestlebot/tasks/rule_transform_task.py +++ b/trestlebot/tasks/rule_transform_task.py @@ -79,7 +79,7 @@ def _transform(self) -> int: def _transform_components(self, component_definition_path: pathlib.Path) -> None: """Transform components into an OSCAL component definition.""" csv_builder: CSVBuilder = CSVBuilder() - logger.debug( + logger.info( f"Transforming rules for component definition {component_definition_path.name}" ) @@ -87,6 +87,7 @@ def _transform_components(self, component_definition_path: pathlib.Path) -> None # pretty print them in a raised exception transformation_errors: List[str] = [] for component in self.iterate_models(component_definition_path): + logger.debug(f"Transforming rules for component {component.name}") for rule_path in self.iterate_models(component): # Load the rule into memory as a stream to process rule_stream = rule_path.read_text()