Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turning off logger at the class-constructor level #323

Merged
merged 20 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/core/zowe/core_for_zowe_sdk/sdk_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 : boolean
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 = True):
aadityasinha-dotcom marked this conversation as resolved.
Show resolved Hide resolved
session = Session(profile)
self.session: ISession = session.load()

self.logger = Log.register_logger(logger_name)

if log == False:
Log.close(self.logger)
aadityasinha-dotcom marked this conversation as resolved.
Show resolved Hide resolved

self._default_service_url = default_url
self._default_headers = {
"Content-Type": "application/json",
Expand Down
4 changes: 2 additions & 2 deletions src/zos_console/zowe/zos_console_for_zowe_sdk/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Console(SdkApi):
A profile in dict (json) format
"""

def __init__(self, connection: dict):
super().__init__(connection, "/zosmf/restconsoles/consoles/defcn", logger_name=__name__)
def __init__(self, connection: dict, log = 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.
Expand Down
4 changes: 2 additions & 2 deletions src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ class Datasets(SdkApi):
A profile for connection in dict (json) format
"""

def __init__(self, connection: dict):
super().__init__(connection, "/zosmf/restfiles/", logger_name=__name__)
def __init__(self, connection: dict, log = 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:
Expand Down
4 changes: 2 additions & 2 deletions src/zos_files/zowe/zos_files_for_zowe_sdk/file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class FileSystems(SdkApi):
A profile for connection in dict (json) format
"""

def __init__(self, connection: dict):
super().__init__(connection, "/zosmf/restfiles/", logger_name=__name__)
def __init__(self, connection: dict, log=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:
Expand Down
4 changes: 2 additions & 2 deletions src/zos_files/zowe/zos_files_for_zowe_sdk/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class Files(SdkApi):
uss: USSFiles
fs: FileSystems

def __init__(self, connection: dict):
super().__init__(connection, "/zosmf/restfiles/", logger_name=__name__)
def __init__(self, connection: dict, log = 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)
Expand Down
4 changes: 2 additions & 2 deletions src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class USSFiles(SdkApi):
The z/OSMF connection object (generated by the ZoweSDK object)
"""

def __init__(self, connection: dict):
super().__init__(connection, "/zosmf/restfiles/", logger_name=__name__)
def __init__(self, connection: dict, log = True):
super().__init__(connection, "/zosmf/restfiles/", logger_name=__name__, log=log)
self._default_headers["Accept-Encoding"] = "gzip"

def list(self, path: str) -> USSListResponse:
Expand Down
4 changes: 2 additions & 2 deletions src/zos_jobs/zowe/zos_jobs_for_zowe_sdk/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class Jobs(SdkApi):
A profile for connection in dict (json) format
"""

def __init__(self, connection: dict):
super().__init__(connection, "/zosmf/restjobs/jobs/", logger_name=__name__)
def __init__(self, connection: dict, log = True):
super().__init__(connection, "/zosmf/restjobs/jobs/", logger_name=__name__, log=log)

def get_job_status(self, jobname: str, jobid: str) -> JobResponse:
"""
Expand Down
4 changes: 2 additions & 2 deletions src/zos_tso/zowe/zos_tso_for_zowe_sdk/tso.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class Tso(SdkApi):
Profile used for tso connection
"""

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 = True):
super().__init__(connection, "/zosmf/tsoApp/tso", logger_name=__name__, log=log)
self.session_not_found = constants["TsoSessionNotFound"]
self.tso_profile = tso_profile or {}

Expand Down
4 changes: 2 additions & 2 deletions src/zosmf/zowe/zosmf_for_zowe_sdk/zosmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class Zosmf(SdkApi):
The z/OSMF connection object (generated by the ZoweSDK object)
"""

def __init__(self, connection: dict):
super().__init__(connection, "/zosmf/info", logger_name=__name__)
def __init__(self, connection: dict, log = True):
super().__init__(connection, "/zosmf/info", logger_name=__name__, log=log)

def get_info(self) -> ZosmfResponse:
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/core/test_sdk_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
aadityasinha-dotcom marked this conversation as resolved.
Show resolved Hide resolved
aadityasinha-dotcom marked this conversation as resolved.
Show resolved Hide resolved
"""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):

Expand Down
Loading