diff --git a/validations_libs/ansible.py b/validations_libs/ansible.py index ce6af3f3..424de272 100644 --- a/validations_libs/ansible.py +++ b/validations_libs/ansible.py @@ -14,7 +14,7 @@ # import ansible_runner -import logging +from validations_libs.logger import getLogger import pkg_resources import pwd import os @@ -27,7 +27,7 @@ import configparser from validations_libs import constants from validations_libs import utils -LOG = logging.getLogger(__name__ + ".ansible") +LOG = getLogger(__name__ + ".ansible") # NOTE(cloudnull): This is setting the FileExistsError for py2 environments. # When we no longer support py2 (centos7) this should be @@ -48,7 +48,7 @@ class Ansible: """An Object for encapsulating an Ansible execution""" def __init__(self, uuid=None): - self.log = logging.getLogger(__name__ + ".Ansible") + self.log = getLogger(__name__ + ".Ansible") self.uuid = uuid def _playbook_check(self, play, playbook_dir=None): diff --git a/validations_libs/cli/common.py b/validations_libs/cli/common.py index 148a0f1b..e4c2d61f 100644 --- a/validations_libs/cli/common.py +++ b/validations_libs/cli/common.py @@ -17,7 +17,7 @@ from argparse import ArgumentDefaultsHelpFormatter from cliff import _argparse import json -import logging +from validations_libs.logger import getLogger from prettytable import PrettyTable import re import sys @@ -92,7 +92,7 @@ def write_output(output_log, results): def write_junitxml(output_junitxml, results): """Write output file as JUnitXML format""" if not JUNIT_XML_FOUND: - log = logging.getLogger(__name__ + ".write_junitxml") + log = getLogger(__name__ + ".write_junitxml") log.warning('junitxml output disabled: the `junit_xml` python module ' 'is missing.') return diff --git a/validations_libs/cli/community.py b/validations_libs/cli/community.py index 9437c8ac..0c9d56ea 100644 --- a/validations_libs/cli/community.py +++ b/validations_libs/cli/community.py @@ -14,7 +14,7 @@ # License for the specific language governing permissions and limitations # under the License. -import logging +from validations_libs.logger import getLogger import os from validations_libs import constants, utils @@ -22,7 +22,7 @@ from validations_libs.cli.base import BaseCommand from validations_libs.community.init_validation import \ CommunityValidation as com_val -LOG = logging.getLogger(__name__) +LOG = getLogger(__name__) class CommunityValidationInit(BaseCommand): diff --git a/validations_libs/community/init_validation.py b/validations_libs/community/init_validation.py index c35601df..99f075dd 100644 --- a/validations_libs/community/init_validation.py +++ b/validations_libs/community/init_validation.py @@ -15,7 +15,7 @@ # under the License. # -import logging +from validations_libs.logger import getLogger import re import os # @matbu backward compatibility for stable/train @@ -26,7 +26,7 @@ except ImportError: from validations_libs import constants, utils -LOG = logging.getLogger(__name__) +LOG = getLogger(__name__) class CommunityValidation: diff --git a/validations_libs/group.py b/validations_libs/group.py index b868ddcc..5e5f4a64 100644 --- a/validations_libs/group.py +++ b/validations_libs/group.py @@ -13,10 +13,10 @@ # under the License. # -import logging +from validations_libs.logger import getLogger import yaml -LOG = logging.getLogger(__name__ + ".Group") +LOG = getLogger(__name__ + ".Group") class Group: diff --git a/validations_libs/tests/test_ansible.py b/validations_libs/tests/test_ansible.py index a61e0489..28f2a962 100644 --- a/validations_libs/tests/test_ansible.py +++ b/validations_libs/tests/test_ansible.py @@ -56,7 +56,7 @@ class TestAnsible(TestCase): self.run = Ansible() self.run.log = mock.MagicMock() - @mock.patch('logging.getLogger') + @mock.patch('validations_libs.ansible.getLogger') def test_ansible_init(self, mock_logger): """ Test of Ansible init. diff --git a/validations_libs/tests/test_validation_actions.py b/validations_libs/tests/test_validation_actions.py index 951a0b3d..80b90617 100644 --- a/validations_libs/tests/test_validation_actions.py +++ b/validations_libs/tests/test_validation_actions.py @@ -536,7 +536,8 @@ class TestValidationActions(TestCase): '2019-11-25T13:40:14.404623Z', '0:00:03.753')]) - @mock.patch('os.stat') + @mock.patch('validations_libs.validation_actions.getLogger') + @mock.patch('validations_libs.validation_actions.os.stat') @mock.patch('validations_libs.validation_logs.ValidationLogs.' 'get_all_logfiles', return_value=[ @@ -546,7 +547,7 @@ class TestValidationActions(TestCase): return_value=fakes.VALIDATIONS_LOGS_CONTENTS_LIST[0]) @mock.patch('builtins.open') def test_show_history_most_recent(self, mock_open, mock_load, - mock_get_log, mock_stat): + mock_get_log, mock_stat, mock_logger): first_validation = mock.MagicMock() second_validation = mock.MagicMock() diff --git a/validations_libs/validation.py b/validations_libs/validation.py index eb18749e..65300b1b 100644 --- a/validations_libs/validation.py +++ b/validations_libs/validation.py @@ -13,12 +13,12 @@ # under the License. # -import logging +from validations_libs.logger import getLogger import os import yaml from collections import OrderedDict -LOG = logging.getLogger(__name__ + ".validation") +LOG = getLogger(__name__ + ".validation") class Validation: diff --git a/validations_libs/validation_actions.py b/validations_libs/validation_actions.py index 2ac923dc..a1275429 100644 --- a/validations_libs/validation_actions.py +++ b/validations_libs/validation_actions.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. # -import logging +from validations_libs.logger import getLogger import os import sys import json @@ -26,7 +26,7 @@ from validations_libs import constants from validations_libs import utils as v_utils from validations_libs.exceptions import ValidationRunException, ValidationShowException -LOG = logging.getLogger(__name__ + ".validation_actions") +LOG = getLogger(__name__ + ".validation_actions") class ValidationActions: @@ -55,7 +55,7 @@ class ValidationActions: (Defaults to ``constants.VALIDATIONS_LOG_BASEDIR``) :type log_path: ``string`` """ - self.log = logging.getLogger(__name__ + ".ValidationActions") + self.log = getLogger(__name__ + ".ValidationActions") self.validation_path = validation_path self.log_path = log_path @@ -119,7 +119,7 @@ class ValidationActions: ['category2'], ['product2'])]) """ - self.log = logging.getLogger(__name__ + ".list_validations") + self.log = getLogger(__name__ + ".list_validations") validations = v_utils.parse_all_validations_on_disk( path=self.validation_path, @@ -177,7 +177,7 @@ class ValidationActions: 'Parameters': {'foo1': bar1} } """ - self.log = logging.getLogger(__name__ + ".show_validations") + self.log = getLogger(__name__ + ".show_validations") # Get validation data: vlog = ValidationLogs(self.log_path) data = v_utils.get_validations_data( @@ -415,7 +415,7 @@ class ValidationActions: 'Unreachable_Hosts': '', 'Validations': 'bar'}] """ - self.log = logging.getLogger(__name__ + ".run_validations") + self.log = getLogger(__name__ + ".run_validations") playbooks = [] validations_dir = (validations_dir if validations_dir else self.validation_path) diff --git a/validations_libs/validation_logs.py b/validations_libs/validation_logs.py index 2f901bb1..3d0d54db 100644 --- a/validations_libs/validation_logs.py +++ b/validations_libs/validation_logs.py @@ -14,14 +14,14 @@ # import json import glob -import logging +from validations_libs.logger import getLogger import os import time from os.path import join from validations_libs import constants -LOG = logging.getLogger(__name__ + ".validation_logs") +LOG = getLogger(__name__ + ".validation_logs") class ValidationLog: @@ -78,8 +78,8 @@ class ValidationLog: self.uuid, _name = self.name.split('_', 1) self.validation_id, self.datetime = _name.rsplit('_', 1) except ValueError: - logging.warning('Wrong log file format, it should be formed ' - 'such as {uuid}_{validation-id}_{timestamp}') + LOG.warning('Wrong log file format, it should be formed ' + 'such as {uuid}_{validation-id}_{timestamp}') def _get_content(self): try: