Skip to content

feat: use module names for loggers #136

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

Merged
merged 2 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 5 additions & 2 deletions ibm_cloud_sdk_core/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
# http_client.HTTPConnection.debuglevel = 1


logger = logging.getLogger(__name__)


#pylint: disable=too-many-instance-attributes
#pylint: disable=too-many-locals
class BaseService:
Expand Down Expand Up @@ -295,7 +298,7 @@ def send(self, request: requests.Request, **kwargs) -> DetailedResponse:
for key in reserved_keys:
if key in kwargs:
del kwargs[key]
logging.warning('"%s" has been removed from the request', key)
logger.warning('"%s" has been removed from the request', key)
try:
response = self.http_client.request(**request,
cookies=self.jar,
Expand All @@ -320,7 +323,7 @@ def send(self, request: requests.Request, **kwargs) -> DetailedResponse:

raise ApiException(response.status_code, http_response=response)
except requests.exceptions.SSLError:
logging.exception(self.ERROR_MSG_DISABLE_SSL)
logger.exception(self.ERROR_MSG_DISABLE_SSL)
raise

def set_enable_gzip_compression(self,
Expand Down
5 changes: 4 additions & 1 deletion ibm_cloud_sdk_core/token_managers/container_token_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
from .iam_request_based_token_manager import IAMRequestBasedTokenManager


logger = logging.getLogger(__name__)


class ContainerTokenManager(IAMRequestBasedTokenManager):
"""The ContainerTokenManager takes a compute resource token and performs the necessary interactions with
the IAM token service to obtain and store a suitable bearer token. Additionally, the ContainerTokenManager
Expand Down Expand Up @@ -110,7 +113,7 @@ def retrieve_cr_token(self) -> str:
"""
cr_token_filename = self.cr_token_filename if self.cr_token_filename else self.DEFAULT_CR_TOKEN_FILENAME

logging.debug('Attempting to read CR token from file: %s',
logger.debug('Attempting to read CR token from file: %s',
cr_token_filename)

try:
Expand Down
11 changes: 7 additions & 4 deletions ibm_cloud_sdk_core/token_managers/vpc_instance_token_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
from .jwt_token_manager import JWTTokenManager


logger = logging.getLogger(__name__)


class VPCInstanceTokenManager(JWTTokenManager):
"""The VPCInstanceTokenManager retrieves an "instance identity token" and exchanges that
for an IAM access token using the VPC Instance Metadata Service API which is available
Expand Down Expand Up @@ -91,15 +94,15 @@ def request_token(self) -> dict:
'Authorization': 'Bearer ' + instance_identity_token
}

logging.debug(
logger.debug(
'Invoking VPC \'create_iam_token\' operation: %s', url)
response = self._request(
method='POST',
url=url,
headers=headers,
params={'version': self.METADATA_SERVICE_VERSION},
data=json.dumps(request_payload) if request_payload else None)
logging.debug('Returned from VPC \'create_iam_token\' operation."')
logger.debug('Returned from VPC \'create_iam_token\' operation."')

return response

Expand Down Expand Up @@ -139,14 +142,14 @@ def retrieve_instance_identity_token(self) -> str:

request_body = {'expires_in': 300}

logging.debug(
logger.debug(
'Invoking VPC \'create_access_token\' operation: %s', url)
response = self._request(
method='PUT',
url=url,
headers=headers,
params={'version': self.METADATA_SERVICE_VERSION},
data=json.dumps(request_body))
logging.debug('Returned from VPC \'create_access_token\' operation."')
logger.debug('Returned from VPC \'create_access_token\' operation."')

return response['access_token']