From 10ea326244831f1a5e93adc6007188f924dd78e2 Mon Sep 17 00:00:00 2001 From: Akash Date: Tue, 23 Jul 2024 11:49:29 +0530 Subject: [PATCH] Update logger initialization to use module-specific loggers #140 Changed "logger = logging.getLogger()" line of code to "logger = logging.getLogger(__name__)" in all files Removed the TODO Comments - "# TODO: At least add __name__ as the name for the logger" in all files https://github.com/StackGuardian/tirith/issues/140 --- src/tirith/cli.py | 4 ++-- src/tirith/core/core.py | 4 ++-- src/tirith/core/evaluators/contained_in.py | 3 +-- src/tirith/core/evaluators/contains.py | 4 ++-- src/tirith/core/evaluators/equals.py | 3 +-- src/tirith/core/evaluators/not_contained_in.py | 4 ++-- src/tirith/core/evaluators/not_contains.py | 4 ++-- src/tirith/core/evaluators/not_equals.py | 3 +-- src/tirith/providers/infracost/handler.py | 3 +-- src/tirith/providers/sg_workflow/handler.py | 4 ++-- src/tirith/providers/terraform_plan/handler.py | 2 +- src/tirith/utils.py | 2 +- 12 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/tirith/cli.py b/src/tirith/cli.py index a666b483..5b3a6840 100755 --- a/src/tirith/cli.py +++ b/src/tirith/cli.py @@ -16,8 +16,8 @@ from .core import start_policy_evaluation -# TODO: Use at least __name__ for the logger name -logger = logging.getLogger() + +logger = logging.getLogger(__name__) def eprint(*args, **kwargs): diff --git a/src/tirith/core/core.py b/src/tirith/core/core.py index c4816c81..15c96657 100644 --- a/src/tirith/core/core.py +++ b/src/tirith/core/core.py @@ -12,8 +12,8 @@ from .evaluators import EVALUATORS_DICT -# TODO: Use __name__ for the logger name instead of using the root logger -logger = logging.getLogger() + +logger = logging.getLogger(__name__) def get_evaluator_inputs_from_provider_inputs(provider_inputs, provider_module, input_data): diff --git a/src/tirith/core/evaluators/contained_in.py b/src/tirith/core/evaluators/contained_in.py index da24a90f..75e61f87 100644 --- a/src/tirith/core/evaluators/contained_in.py +++ b/src/tirith/core/evaluators/contained_in.py @@ -3,8 +3,7 @@ from .base_evaluator import BaseEvaluator from tirith.utils import sort_collections -# TODO: At least add __name__ as the name for the logger -logger = logging.getLogger() +logger = logging.getLogger(__name__) # Checks if :attr: `evaluator_input` is contained in :attr:`evaluator_data`. diff --git a/src/tirith/core/evaluators/contains.py b/src/tirith/core/evaluators/contains.py index 8313fc81..ba83f7a6 100644 --- a/src/tirith/core/evaluators/contains.py +++ b/src/tirith/core/evaluators/contains.py @@ -3,8 +3,8 @@ from .base_evaluator import BaseEvaluator from tirith.utils import sort_collections -# TODO: At least add __name__ as the name for the logger -logger = logging.getLogger() + +logger = logging.getLogger(__name__) # Checks if :attr: `evaluator_input` is contained in :attr:`evaluator_data`. diff --git a/src/tirith/core/evaluators/equals.py b/src/tirith/core/evaluators/equals.py index 193747ad..bdd4f1b1 100644 --- a/src/tirith/core/evaluators/equals.py +++ b/src/tirith/core/evaluators/equals.py @@ -3,8 +3,7 @@ from .base_evaluator import BaseEvaluator from tirith.utils import sort_collections -# TODO: Use __name__ for the logger name instead of using the root logger -logger = logging.getLogger() +logger = logging.getLogger(__name__) # Checks if :attr:`value` is equal to :attr:`other`. Automatically casts values to the same type if possible. diff --git a/src/tirith/core/evaluators/not_contained_in.py b/src/tirith/core/evaluators/not_contained_in.py index 216bc222..7261cb87 100644 --- a/src/tirith/core/evaluators/not_contained_in.py +++ b/src/tirith/core/evaluators/not_contained_in.py @@ -3,8 +3,8 @@ from .base_evaluator import BaseEvaluator from tirith.utils import sort_collections -# TODO: At least add __name__ as the name for the logger -logger = logging.getLogger() + +logger = logging.getLogger(__name__) # Checks if :attr: `evaluator_input` is not contained in :attr:`evaluator_data`. diff --git a/src/tirith/core/evaluators/not_contains.py b/src/tirith/core/evaluators/not_contains.py index f696f535..7f336a69 100644 --- a/src/tirith/core/evaluators/not_contains.py +++ b/src/tirith/core/evaluators/not_contains.py @@ -3,8 +3,8 @@ from .base_evaluator import BaseEvaluator from tirith.utils import sort_collections -# TODO: At least add __name__ as the name for the logger -logger = logging.getLogger() + +logger = logging.getLogger(__name__) # Checks if :attr: `evaluator_input` does not contain :attr:`evaluator_data`. diff --git a/src/tirith/core/evaluators/not_equals.py b/src/tirith/core/evaluators/not_equals.py index d8d57b43..516ecb07 100644 --- a/src/tirith/core/evaluators/not_equals.py +++ b/src/tirith/core/evaluators/not_equals.py @@ -3,8 +3,7 @@ from .base_evaluator import BaseEvaluator from tirith.utils import sort_collections -# TODO: Use __name__ for the logger name instead of using the root logger -logger = logging.getLogger() +logger = logging.getLogger(__name__) # Checks if :attr:`value` is not equal to :attr:`other`. Automatically casts values to the same type if possible. diff --git a/src/tirith/providers/infracost/handler.py b/src/tirith/providers/infracost/handler.py index fbeac3ab..dd6c84e7 100644 --- a/src/tirith/providers/infracost/handler.py +++ b/src/tirith/providers/infracost/handler.py @@ -1,7 +1,6 @@ import logging -# TODO: Add at least __name__ as the name of the logger -logger = logging.getLogger() +logger = logging.getLogger(__name__) def __get_all_costs(operation_type, input_data): diff --git a/src/tirith/providers/sg_workflow/handler.py b/src/tirith/providers/sg_workflow/handler.py index bc99e66b..29c1d9d0 100644 --- a/src/tirith/providers/sg_workflow/handler.py +++ b/src/tirith/providers/sg_workflow/handler.py @@ -1,7 +1,7 @@ import logging -# TODO: Add at least __name__ as the name of the logger -logger = logging.getLogger() + +logger = logging.getLogger(__name__) def __getValue(key, data): diff --git a/src/tirith/providers/terraform_plan/handler.py b/src/tirith/providers/terraform_plan/handler.py index 3b7a3166..8c71f08c 100644 --- a/src/tirith/providers/terraform_plan/handler.py +++ b/src/tirith/providers/terraform_plan/handler.py @@ -43,7 +43,7 @@ def _get_exp_attribute(split_expressions, input_data): final_data.append(val) return final_data - + def provide(provider_inputs, input_data): # """Provides the value of the attribute from the input_data""" outputs = [] diff --git a/src/tirith/utils.py b/src/tirith/utils.py index 09722781..de83bf1e 100644 --- a/src/tirith/utils.py +++ b/src/tirith/utils.py @@ -1,6 +1,6 @@ import logging -logger = logging.getLogger() +logger = logging.getLogger(__name__) def sort_collections(inputs):