diff --git a/img/zowesdk.gif b/img/zowesdk.gif old mode 100755 new mode 100644 index 2677fd74..cce98000 Binary files a/img/zowesdk.gif and b/img/zowesdk.gif differ diff --git a/src/core/zowe/core_for_zowe_sdk/config_file.py b/src/core/zowe/core_for_zowe_sdk/config_file.py index 60cab57e..b0a4910e 100644 --- a/src/core/zowe/core_for_zowe_sdk/config_file.py +++ b/src/core/zowe/core_for_zowe_sdk/config_file.py @@ -28,6 +28,7 @@ from .exceptions import ProfileNotFound from .profile_constants import GLOBAL_CONFIG_NAME, TEAM_CONFIG, USER_CONFIG from .validators import validate_config_json +from .logger import Log HOME = os.path.expanduser("~") GLOBAL_CONFIG_LOCATION = os.path.join(HOME, ".zowe") @@ -73,7 +74,7 @@ class ConfigFile: jsonc: Optional[dict] = None _missing_secure_props: list = field(default_factory=list) - __logger = logging.getLogger(__name__) + __logger = Log.registerLogger(__name__) @property def filename(self) -> str: @@ -212,7 +213,7 @@ def get_profile( self.init_from_file(validate_schema) if profile_name is None and profile_type is None: - self.__logger.error(f"Failed to load profile '{profile_name}' because Could not find profile as both profile_name and profile_type is not set") + self.__logger.error(f"Failed to load profile: profile_name and profile_type were not provided.") raise ProfileNotFound( profile_name=profile_name, error_msg="Could not find profile as both profile_name and profile_type is not set.", diff --git a/src/core/zowe/core_for_zowe_sdk/connection.py b/src/core/zowe/core_for_zowe_sdk/connection.py index 2f764a99..41c7e553 100644 --- a/src/core/zowe/core_for_zowe_sdk/connection.py +++ b/src/core/zowe/core_for_zowe_sdk/connection.py @@ -11,6 +11,7 @@ """ from .exceptions import MissingConnectionArgs +from .logger import Log import logging @@ -30,7 +31,7 @@ class ApiConnection: """ def __init__(self, host_url, user, password, ssl_verification=True): - logger = logging.getLogger(__name__) + logger = Log.registerLogger(__name__) """Construct an ApiConnection object.""" if not host_url or not user or not password: diff --git a/src/core/zowe/core_for_zowe_sdk/credential_manager.py b/src/core/zowe/core_for_zowe_sdk/credential_manager.py index fac1f631..74787194 100644 --- a/src/core/zowe/core_for_zowe_sdk/credential_manager.py +++ b/src/core/zowe/core_for_zowe_sdk/credential_manager.py @@ -20,6 +20,7 @@ from .constants import constants from .exceptions import SecureProfileLoadFailed +from .logger import Log HAS_KEYRING = True try: @@ -30,7 +31,7 @@ class CredentialManager: secure_props = {} - __logger = logging.getLogger(__name__) + __logger = Log.registerLogger(__name__) @staticmethod def load_secure_props() -> None: diff --git a/src/core/zowe/core_for_zowe_sdk/logger.py b/src/core/zowe/core_for_zowe_sdk/logger.py index 3ef9b3b6..3549ec11 100644 --- a/src/core/zowe/core_for_zowe_sdk/logger.py +++ b/src/core/zowe/core_for_zowe_sdk/logger.py @@ -2,7 +2,7 @@ import os class Log: - """root logger setup and a funtion to customize logger level""" + """root logger setup and a function to customize logger level""" dirname = os.path.join(os.path.expanduser("~"), ".zowe/logs") @@ -18,7 +18,10 @@ class Log: loggers = [] @staticmethod def registerLogger(name: str): - Log.loggers.append(logging.getLogger(name)) + """A function to get Logger and registered for level setting""" + logger = logging.getLogger(name) + Log.loggers.append(logger) + return logger @staticmethod def setLoggerLevel(level: int): diff --git a/src/core/zowe/core_for_zowe_sdk/profile_manager.py b/src/core/zowe/core_for_zowe_sdk/profile_manager.py index fc639c82..0cea790d 100644 --- a/src/core/zowe/core_for_zowe_sdk/profile_manager.py +++ b/src/core/zowe/core_for_zowe_sdk/profile_manager.py @@ -59,8 +59,7 @@ def __init__(self, appname: str = "zowe", show_warnings: bool = True): self.project_config = ConfigFile(type=TEAM_CONFIG, name=appname) self.project_user_config = ConfigFile(type=USER_CONFIG, name=appname) - self.__logger = logging.getLogger(__name__) - Log.registerLogger(__name__) + self.__logger = Log.registerLogger(__name__) self.global_config = ConfigFile(type=TEAM_CONFIG, name=GLOBAL_CONFIG_NAME) try: @@ -200,7 +199,7 @@ def get_profile( f"A type checker was asked to check a type it did not have registered, {exc}" ) except jsonschema.exceptions.UnknownType as exc: - logger.error(f"Unknown type is found in schema_json, exc") + logger.error(f"Unknown type is found in schema_json, {exc}") raise jsonschema.exceptions.UnknownType(f"Unknown type is found in schema_json, exc") except jsonschema.exceptions.FormatError as exc: logger.error(f"Validating a format config_json failed for schema_json, {exc}") diff --git a/src/core/zowe/core_for_zowe_sdk/request_handler.py b/src/core/zowe/core_for_zowe_sdk/request_handler.py index 47455286..20791ceb 100644 --- a/src/core/zowe/core_for_zowe_sdk/request_handler.py +++ b/src/core/zowe/core_for_zowe_sdk/request_handler.py @@ -15,6 +15,7 @@ import logging from .exceptions import InvalidRequestMethod, RequestFailed, UnexpectedStatus +from .logger import Log class RequestHandler: @@ -44,7 +45,7 @@ def __init__(self, session_arguments, logger_name = __name__): self.session_arguments = session_arguments self.valid_methods = ["GET", "POST", "PUT", "DELETE"] self.__handle_ssl_warnings() - self.__logger = logging.getLogger(logger_name) + self.__logger = Log.registerLogger(__name__) def __handle_ssl_warnings(self): """Turn off warnings if the SSL verification argument if off.""" diff --git a/src/core/zowe/core_for_zowe_sdk/sdk_api.py b/src/core/zowe/core_for_zowe_sdk/sdk_api.py index acb83ac3..dae4fc29 100644 --- a/src/core/zowe/core_for_zowe_sdk/sdk_api.py +++ b/src/core/zowe/core_for_zowe_sdk/sdk_api.py @@ -17,6 +17,7 @@ from .exceptions import UnsupportedAuthType from .request_handler import RequestHandler from .session import ISession, Session +from .logger import Log class SdkApi: @@ -29,7 +30,7 @@ def __init__(self, profile, default_url, logger_name = __name__): session = Session(profile) self.session: ISession = session.load() - self.logger = logging.getLogger(logger_name) + self.logger = Log.registerLogger(logger_name) self.default_service_url = default_url self.default_headers = { diff --git a/src/core/zowe/core_for_zowe_sdk/session.py b/src/core/zowe/core_for_zowe_sdk/session.py index fe2ac533..fa2861bc 100644 --- a/src/core/zowe/core_for_zowe_sdk/session.py +++ b/src/core/zowe/core_for_zowe_sdk/session.py @@ -14,8 +14,8 @@ from typing import Optional from . import session_constants +from .logger import Log -import logging @dataclass class ISession: @@ -43,7 +43,7 @@ class Session: def __init__(self, props: dict) -> None: # set host and port - self.__logger = logging.getLogger(__name__) + self.__logger = Log.registerLogger(__name__) if props.get("host") is not None: self.session: ISession = ISession(host=props.get("host")) diff --git a/src/core/zowe/core_for_zowe_sdk/zosmf_profile.py b/src/core/zowe/core_for_zowe_sdk/zosmf_profile.py index b877fdea..d9aa1893 100644 --- a/src/core/zowe/core_for_zowe_sdk/zosmf_profile.py +++ b/src/core/zowe/core_for_zowe_sdk/zosmf_profile.py @@ -16,11 +16,10 @@ import yaml -import logging - from .connection import ApiConnection from .constants import constants from .exceptions import SecureProfileLoadFailed +from .logger import Log HAS_KEYRING = True try: @@ -55,7 +54,7 @@ def __init__(self, profile_name): The name of the Zowe z/OSMF profile """ self.profile_name = profile_name - self.__logger = logging.getLogger(__name__) + self.__logger = Log.registerLogger(__name__) @property def profiles_dir(self): diff --git a/tests/unit/test_zowe_core.py b/tests/unit/test_zowe_core.py index 4e216fec..459a52ad 100644 --- a/tests/unit/test_zowe_core.py +++ b/tests/unit/test_zowe_core.py @@ -453,7 +453,7 @@ def test_profile_empty_exception(self, get_pass_func, mock_logger_error: mock.Ma self.setUpCreds(cwd_up_file_path, secure_props={}) config_file = ConfigFile(name=self.custom_appname, type="team_config") props: dict = config_file.get_profile(profile_name=None,profile_type=None,validate_schema=False) - self.assertEqual(mock_logger_error.call_args[0][0], "Failed to load profile 'None' because Could not find profile as both profile_name and profile_type is not set") + self.assertEqual(mock_logger_error.call_args[0][0], "Failed to load profile: profile_name and profile_type were not provided.") @mock.patch("logging.Logger.error") @mock.patch("logging.Logger.warning")