Skip to content

Commit

Permalink
Update registerLogger and related code
Browse files Browse the repository at this point in the history
Signed-off-by: pem70 <[email protected]>
  • Loading branch information
pem70 committed May 30, 2024
1 parent 0c70479 commit c7a64ff
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/core/zowe/core_for_zowe_sdk/config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/core/zowe/core_for_zowe_sdk/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

from .exceptions import MissingConnectionArgs
from .logger import Log
import logging


Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/core/zowe/core_for_zowe_sdk/credential_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from .constants import constants
from .exceptions import SecureProfileLoadFailed
from .logger import Log

HAS_KEYRING = True
try:
Expand All @@ -30,7 +31,7 @@

class CredentialManager:
secure_props = {}
__logger = logging.getLogger(__name__)
__logger = Log.registerLogger(__name__)

@staticmethod
def load_secure_props() -> None:
Expand Down
5 changes: 4 additions & 1 deletion src/core/zowe/core_for_zowe_sdk/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions src/core/zowe/core_for_zowe_sdk/profile_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/core/zowe/core_for_zowe_sdk/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import logging

from .exceptions import InvalidRequestMethod, RequestFailed, UnexpectedStatus
from .logger import Log


class RequestHandler:
Expand Down Expand Up @@ -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."""
Expand Down
3 changes: 2 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 @@ -17,6 +17,7 @@
from .exceptions import UnsupportedAuthType
from .request_handler import RequestHandler
from .session import ISession, Session
from .logger import Log


class SdkApi:
Expand All @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions src/core/zowe/core_for_zowe_sdk/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from typing import Optional

from . import session_constants
from .logger import Log

import logging

@dataclass
class ISession:
Expand Down Expand Up @@ -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"))
Expand Down
5 changes: 2 additions & 3 deletions src/core/zowe/core_for_zowe_sdk/zosmf_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c7a64ff

Please sign in to comment.