Skip to content

Commit 35e6ce1

Browse files
author
wallisyan
committed
modify add_logger
1 parent 92a3e45 commit 35e6ce1

File tree

7 files changed

+17
-23
lines changed

7 files changed

+17
-23
lines changed

aliyun-python-sdk-core/aliyunsdkcore/auth/signers/access_key_signer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def __init__(self, access_key_credential):
3030
self._credential = access_key_credential
3131

3232
def sign(self, region_id, request):
33-
logger.debug("Calculating signature using AccessKey.")
3433
cred = self._credential
3534
header = request.get_signed_header(region_id, cred.access_key_id, cred.access_key_secret)
3635
url = request.get_url(region_id, cred.access_key_id, cred.access_key_secret)

aliyun-python-sdk-core/aliyunsdkcore/auth/signers/ecs_ram_role_signer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def __init__(self, ecs_ram_role_credential):
3939
self._expiration = 0
4040

4141
def sign(self, region_id, request):
42-
logger.debug("Calculating signature using EcsRamRole.")
4342
self._check_session_credential()
4443
session_ak, session_sk, token = self._session_credential
4544
if request.get_style() == 'RPC':

aliyun-python-sdk-core/aliyunsdkcore/auth/signers/ram_role_arn_signer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ def __init__(self, credential, do_action_api):
5050
self._credential.session_role_name = "aliyun-python-sdk-" + str(time.time())
5151

5252
def sign(self, region_id, request):
53-
logger.debug("Calculating signature using RamRoleArn.")
5453
self._check_session_credential()
5554
session_ak, session_sk, token = self._session_credential
5655
if request.get_style() == 'RPC':

aliyun-python-sdk-core/aliyunsdkcore/auth/signers/rsa_key_pair_signer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def __init__(self, credential, region_id, debug=False):
3939
self._session_credential = None
4040

4141
def sign(self, region_id, request):
42-
logger.debug("Calculating signature using RsaKeyPair.")
4342
self._check_session_credential()
4443
session_ak, session_sk = self._session_credential
4544
header = request.get_signed_header(region_id, session_ak, session_sk)

aliyun-python-sdk-core/aliyunsdkcore/auth/signers/sts_token_signer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def __init__(self, sts_credential):
3131
self._credential = sts_credential
3232

3333
def sign(self, region_id, request):
34-
logger.debug("Calculating signature using StsToken.")
3534
sts_cred = self._credential
3635
if request.get_style() == 'RPC':
3736
request.add_query_param("SecurityToken", sts_cred.sts_token)

aliyun-python-sdk-core/aliyunsdkcore/client.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import json
2424
import logging
2525
import jmespath
26+
import copy
2627

2728
import aliyunsdkcore
2829
from aliyunsdkcore.vendored.six.moves.urllib.parse import urlencode
@@ -59,7 +60,7 @@
5960

6061

6162
class AcsClient:
62-
LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
63+
LOG_FORMAT = '%(thread)d %(asctime)s %(name)s %(levelname)s %(message)s'
6364

6465
def __init__(
6566
self,
@@ -270,10 +271,10 @@ def _handle_retry_and_timeout(self, endpoint, request, signer):
270271
retryable = self._retry_policy.should_retry(retry_policy_context)
271272
if retryable & RetryCondition.NO_RETRY:
272273
break
273-
logger.debug("Retry needed, request is: %s", request.get_action_name())
274+
logger.debug("Retry needed Request:%s Retries :%d",
275+
request.get_action_name(), retries)
274276
retry_policy_context.retryable = retryable
275277
time_to_sleep = self._retry_policy.compute_delay_before_next_retry(retry_policy_context)
276-
logger.debug('Retry %s times', retries)
277278
time.sleep(time_to_sleep / 1000.0)
278279
retries += 1
279280

@@ -284,20 +285,18 @@ def _handle_retry_and_timeout(self, endpoint, request, signer):
284285

285286
def _handle_single_request(self, endpoint, request, timeout, signer):
286287
http_response = self._make_http_response(endpoint, request, timeout, signer)
287-
params = request.get_query_params()
288+
params = copy.deepcopy(request.get_query_params())
288289
params.pop('AccessKeyId', None)
289-
logger.debug('The request params are %s', str(params))
290+
logger.debug('Request params are %s', str(params))
290291

291292
# Do the actual network thing
292293
try:
293294
status, headers, body = http_response.get_response_object()
294295
except IOError as e:
295-
error_message = str(e)
296-
error_message += "\nEndpoint: " + endpoint
297-
logger.error('Catch a HttpError when connect to %s, current sdk version is %s',
298-
endpoint, aliyunsdkcore.__version__, exc_info=True)
296+
logger.error("HttpError occurred Host:%s SDK-Version:%s",
297+
endpoint, aliyunsdkcore.__version__)
299298

300-
exception = ClientException(error_code.SDK_HTTP_ERROR, error_message)
299+
exception = ClientException(error_code.SDK_HTTP_ERROR, str(e))
301300
return None, None, None, exception
302301

303302
exception = self._get_server_exception(status, body)
@@ -316,7 +315,7 @@ def _parse_error_info_from_response_body(response_body):
316315
error_message_to_return = body_obj['Message']
317316
except ValueError:
318317
# failed to parse body as json format
319-
logger.warning('failed to parse response body as json format')
318+
logger.warning('Failed to parse Response:%s as json format.', response_body)
320319

321320
return error_code_to_return, error_message_to_return
322321

@@ -329,7 +328,7 @@ def _get_server_exception(self, http_status, response_body):
329328
except (ValueError, TypeError, AttributeError):
330329
# in case the response body is not a json string, return the raw
331330
# data instead
332-
logger.warning('failed to parse response body as json format')
331+
logger.warning('Failed to parse Response:%s as json format.', response_body)
333332

334333
if http_status < codes.OK or http_status >= codes.MULTIPLE_CHOICES:
335334

aliyun-python-sdk-core/aliyunsdkcore/retry/retry_condition.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def should_retry(self, retry_policy_context):
6262
if retry_policy_context.retries_attempted < self.max_retry_times:
6363
return RetryCondition.SHOULD_RETRY
6464
else:
65-
logger.debug("Reached the maximum number of retry "
66-
"attempts: %s", retry_policy_context.retries_attempted)
65+
logger.debug("Reached the maximum number of retry,Attempts:%d",
66+
retry_policy_context.retries_attempted)
6767
return RetryCondition.NO_RETRY
6868

6969

@@ -78,7 +78,7 @@ def should_retry(self, retry_policy_context):
7878

7979
if isinstance(exception, ClientException):
8080
if exception.get_error_code() == error_code.SDK_HTTP_ERROR:
81-
logger.debug("Retry needed, retryable ClientException caught: %s",
81+
logger.debug("Retryable ClientException occurred,ClientException:%s",
8282
exception, exc_info=True)
8383
return RetryCondition.SHOULD_RETRY
8484

@@ -88,15 +88,15 @@ def should_retry(self, retry_policy_context):
8888
request,
8989
self.retry_config)
9090
if isinstance(normal_errors, list) and error_code_ in normal_errors:
91-
logger.debug("Retry needed, retryable ServerException caught: %s",
91+
logger.debug("Retryable ServerException occurred,ServerException:%s",
9292
exception, exc_info=True)
9393
return RetryCondition.SHOULD_RETRY
9494

9595
throttling_errors = _find_data_in_retry_config("RetryableThrottlingErrors",
9696
request,
9797
self.retry_config)
9898
if isinstance(throttling_errors, list) and error_code_ in throttling_errors:
99-
logger.debug("Retry needed, retryable ThrottlingError caught: %s",
99+
logger.debug("Retryable ThrottlingError occurred,ThrottlingError:%s",
100100
exception, exc_info=True)
101101
return RetryCondition.SHOULD_RETRY | \
102102
RetryCondition.SHOULD_RETRY_WITH_THROTTLING_BACKOFF
@@ -119,7 +119,7 @@ def __init__(self, retryable_http_status_list=None):
119119
def should_retry(self, retry_policy_context):
120120
if retry_policy_context.http_status_code in self.retryable_http_status_list:
121121
logger.debug(
122-
"Retry needed: retryable HTTP status code received: %s",
122+
"Retryable HTTP error occurred,HTTP status code: %s",
123123
retry_policy_context.http_status_code)
124124
return RetryCondition.SHOULD_RETRY
125125
else:

0 commit comments

Comments
 (0)