diff --git a/CHANGELOG.md b/CHANGELOG.md index 96698cd6..d118fa03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,19 @@ All notable changes to the Zowe Client Python SDK will be documented in this file. +## Recent Changes + +### Enhancements + +- Turning of logger at the class-constructor level [#316] (https://github.com/zowe/zowe-client-python-sdk/issues/316) + ## `1.0.0-dev21` ### Bug Fixes - Fixed Core SDK package referencing a non-existent version of Secrets SDK. + ## `1.0.0-dev20` ### Enhancements diff --git a/src/core/zowe/core_for_zowe_sdk/logger.py b/src/core/zowe/core_for_zowe_sdk/logger.py index c3f2cd7c..06421d62 100644 --- a/src/core/zowe/core_for_zowe_sdk/logger.py +++ b/src/core/zowe/core_for_zowe_sdk/logger.py @@ -20,8 +20,6 @@ class Log: Attributes ---------- - loggers: set - The set of all loggers dirname: str Path where the log file is saved file_handler: logging.FileHandler @@ -32,6 +30,8 @@ class Log: Specifies whether log messages would be saved to a file. True by default. console_output: bool Specifies whether log messages would be printed out on console. True by default. + loggers: set + The set of all loggers """ dirname: str = os.path.join(os.path.expanduser("~"), ".zowe/logs") 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 31494889..c11a6948 100644 --- a/src/core/zowe/core_for_zowe_sdk/sdk_api.py +++ b/src/core/zowe/core_for_zowe_sdk/sdk_api.py @@ -31,14 +31,19 @@ class SdkApi: Default url used for session logger_name : str Name of the logger (same as the filename by default) + log : bool + Flag to disable logger """ - def __init__(self, profile: dict, default_url: str, logger_name: str = __name__): + def __init__(self, profile: dict, default_url: str, logger_name: str = __name__, log: bool = True): session = Session(profile) self.session: ISession = session.load() self.logger = Log.register_logger(logger_name) + if log == False: + Log.close(self.logger) + self._default_service_url = default_url self._default_headers = { "Content-Type": "application/json", diff --git a/src/zos_console/zowe/zos_console_for_zowe_sdk/console.py b/src/zos_console/zowe/zos_console_for_zowe_sdk/console.py index a7fdfb38..7f14050f 100644 --- a/src/zos_console/zowe/zos_console_for_zowe_sdk/console.py +++ b/src/zos_console/zowe/zos_console_for_zowe_sdk/console.py @@ -25,10 +25,12 @@ class Console(SdkApi): ---------- connection : dict A profile in dict (json) format + log : bool + Flag to disable logger """ - def __init__(self, connection: dict): - super().__init__(connection, "/zosmf/restconsoles/consoles/defcn", logger_name=__name__) + def __init__(self, connection: dict, log: bool = True): + super().__init__(connection, "/zosmf/restconsoles/consoles/defcn", logger_name=__name__, log=log) def issue_command(self, command: str, console: Optional[str] = None) -> IssueCommandResponse: """Issues a command on z/OS Console. diff --git a/src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py b/src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py index 6e2d120b..32057878 100644 --- a/src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py +++ b/src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py @@ -301,10 +301,12 @@ class Datasets(SdkApi): ---------- connection : dict A profile for connection in dict (json) format + log : bool + Flag to disable logger """ - def __init__(self, connection: dict): - super().__init__(connection, "/zosmf/restfiles/", logger_name=__name__) + def __init__(self, connection: dict, log: bool = True): + super().__init__(connection, "/zosmf/restfiles/", logger_name=__name__, log=log) self._default_headers["Accept-Encoding"] = "gzip" def list(self, name_pattern: str, return_attributes: bool = False) -> DatasetListResponse: diff --git a/src/zos_files/zowe/zos_files_for_zowe_sdk/file_system.py b/src/zos_files/zowe/zos_files_for_zowe_sdk/file_system.py index eb0bc99f..db007dca 100644 --- a/src/zos_files/zowe/zos_files_for_zowe_sdk/file_system.py +++ b/src/zos_files/zowe/zos_files_for_zowe_sdk/file_system.py @@ -30,10 +30,12 @@ class FileSystems(SdkApi): ---------- connection : dict A profile for connection in dict (json) format + log : bool + Flag to disable logger """ - def __init__(self, connection: dict): - super().__init__(connection, "/zosmf/restfiles/", logger_name=__name__) + def __init__(self, connection: dict, log: bool = True): + super().__init__(connection, "/zosmf/restfiles/", logger_name=__name__, log=log) self._default_headers["Accept-Encoding"] = "gzip" def create(self, file_system_name: str, options: dict = {}) -> dict: diff --git a/src/zos_files/zowe/zos_files_for_zowe_sdk/files.py b/src/zos_files/zowe/zos_files_for_zowe_sdk/files.py index d0713d5d..0bf56c86 100644 --- a/src/zos_files/zowe/zos_files_for_zowe_sdk/files.py +++ b/src/zos_files/zowe/zos_files_for_zowe_sdk/files.py @@ -39,14 +39,16 @@ class Files(SdkApi): ---------- connection: dict The z/OSMF connection object (generated by the ZoweSDK object) + log : bool + Flag to disable logger """ ds: Datasets uss: USSFiles fs: FileSystems - def __init__(self, connection: dict): - super().__init__(connection, "/zosmf/restfiles/", logger_name=__name__) + def __init__(self, connection: dict, log: bool = True): + super().__init__(connection, "/zosmf/restfiles/", logger_name=__name__, log=log) self._default_headers["Accept-Encoding"] = "gzip" self.ds = Datasets(connection) self.uss = USSFiles(connection) diff --git a/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py b/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py index e694e807..4be1f732 100644 --- a/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py +++ b/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py @@ -32,10 +32,12 @@ class USSFiles(SdkApi): ---------- connection: dict The z/OSMF connection object (generated by the ZoweSDK object) + log : bool + Flag to disable logger """ - def __init__(self, connection: dict): - super().__init__(connection, "/zosmf/restfiles/", logger_name=__name__) + def __init__(self, connection: dict, log: bool = True): + super().__init__(connection, "/zosmf/restfiles/", logger_name=__name__, log=log) self._default_headers["Accept-Encoding"] = "gzip" def list(self, path: str) -> USSListResponse: diff --git a/src/zos_jobs/zowe/zos_jobs_for_zowe_sdk/jobs.py b/src/zos_jobs/zowe/zos_jobs_for_zowe_sdk/jobs.py index 65659d9e..1ae81fab 100644 --- a/src/zos_jobs/zowe/zos_jobs_for_zowe_sdk/jobs.py +++ b/src/zos_jobs/zowe/zos_jobs_for_zowe_sdk/jobs.py @@ -28,10 +28,12 @@ class Jobs(SdkApi): ---------- connection : dict A profile for connection in dict (json) format + log : bool + Flag to disable logger """ - def __init__(self, connection: dict): - super().__init__(connection, "/zosmf/restjobs/jobs/", logger_name=__name__) + def __init__(self, connection: dict, log: bool = True): + super().__init__(connection, "/zosmf/restjobs/jobs/", logger_name=__name__, log=log) def get_job_status(self, jobname: str, jobid: str) -> JobResponse: """ diff --git a/src/zos_tso/zowe/zos_tso_for_zowe_sdk/tso.py b/src/zos_tso/zowe/zos_tso_for_zowe_sdk/tso.py index f67f7c15..b0e16471 100644 --- a/src/zos_tso/zowe/zos_tso_for_zowe_sdk/tso.py +++ b/src/zos_tso/zowe/zos_tso_for_zowe_sdk/tso.py @@ -28,10 +28,12 @@ class Tso(SdkApi): Connection object tso_profile: Optional[dict] Profile used for tso connection + log : bool + Flag to disable logger """ - def __init__(self, connection: dict, tso_profile: Optional[dict] = None): - super().__init__(connection, "/zosmf/tsoApp/tso", logger_name=__name__) + def __init__(self, connection: dict, tso_profile: Optional[dict] = None, log: bool = True): + super().__init__(connection, "/zosmf/tsoApp/tso", logger_name=__name__, log=log) self.session_not_found = constants["TsoSessionNotFound"] self.tso_profile = tso_profile or {} diff --git a/src/zosmf/zowe/zosmf_for_zowe_sdk/zosmf.py b/src/zosmf/zowe/zosmf_for_zowe_sdk/zosmf.py index 05691827..5c4f26b1 100644 --- a/src/zosmf/zowe/zosmf_for_zowe_sdk/zosmf.py +++ b/src/zosmf/zowe/zosmf_for_zowe_sdk/zosmf.py @@ -23,10 +23,12 @@ class Zosmf(SdkApi): ---------- connection: dict The z/OSMF connection object (generated by the ZoweSDK object) + log : bool + Flag to disable logger """ - def __init__(self, connection: dict): - super().__init__(connection, "/zosmf/info", logger_name=__name__) + def __init__(self, connection: dict, log: bool = True): + super().__init__(connection, "/zosmf/info", logger_name=__name__, log=log) def get_info(self) -> ZosmfResponse: """ diff --git a/tests/unit/core/test_sdk_api.py b/tests/unit/core/test_sdk_api.py index 374225dd..174fd522 100644 --- a/tests/unit/core/test_sdk_api.py +++ b/tests/unit/core/test_sdk_api.py @@ -25,6 +25,11 @@ def test_object_should_be_instance_of_class(self): sdk_api = SdkApi(self.basic_props, self.default_url) self.assertIsInstance(sdk_api, SdkApi) + def test_object_should_be_instance_with_logger_set_to_false(self): + """Created object should be instance with logger set to False of SdkApi class.""" + sdk_api = SdkApi(self.basic_props, self.default_url, log=False) + self.assertEqual(sdk_api.logger.disabled, True) + @mock.patch("requests.Session.close") def test_context_manager_closes_session(self, mock_close_request):