Skip to content

Commit feac129

Browse files
author
wallisyan
committed
modify logger infomations
modify lint:line too long disable all requests logs
1 parent 35e6ce1 commit feac129

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "2.12.1"
1+
__version__ = "2.13.0"
22

33
import logging
44

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def _handle_retry_and_timeout(self, endpoint, request, signer):
271271
retryable = self._retry_policy.should_retry(retry_policy_context)
272272
if retryable & RetryCondition.NO_RETRY:
273273
break
274-
logger.debug("Retry needed Request:%s Retries :%d",
274+
logger.debug("Retry needed. Request:%s Retries :%d",
275275
request.get_action_name(), retries)
276276
retry_policy_context.retryable = retryable
277277
time_to_sleep = self._retry_policy.compute_delay_before_next_retry(retry_policy_context)
@@ -287,19 +287,20 @@ def _handle_single_request(self, endpoint, request, timeout, signer):
287287
http_response = self._make_http_response(endpoint, request, timeout, signer)
288288
params = copy.deepcopy(request.get_query_params())
289289
params.pop('AccessKeyId', None)
290-
logger.debug('Request params are %s', str(params))
290+
logger.debug('Request received. Product:%s Endpoint:%s Params: %s',
291+
request.get_product(), endpoint, str(params))
291292

292293
# Do the actual network thing
293294
try:
294295
status, headers, body = http_response.get_response_object()
295296
except IOError as e:
296-
logger.error("HttpError occurred Host:%s SDK-Version:%s",
297-
endpoint, aliyunsdkcore.__version__)
298297

299298
exception = ClientException(error_code.SDK_HTTP_ERROR, str(e))
299+
logger.error("HttpError occurred. Host:%s SDK-Version:%s ClientException:%s",
300+
endpoint, aliyunsdkcore.__version__, str(exception))
300301
return None, None, None, exception
301302

302-
exception = self._get_server_exception(status, body)
303+
exception = self._get_server_exception(status, body, endpoint)
303304
return status, headers, body, exception
304305

305306
@staticmethod
@@ -315,11 +316,11 @@ def _parse_error_info_from_response_body(response_body):
315316
error_message_to_return = body_obj['Message']
316317
except ValueError:
317318
# failed to parse body as json format
318-
logger.warning('Failed to parse Response:%s as json format.', response_body)
319+
logger.warning('Failed to parse response as json format. Response:%s', response_body)
319320

320321
return error_code_to_return, error_message_to_return
321322

322-
def _get_server_exception(self, http_status, response_body):
323+
def _get_server_exception(self, http_status, response_body, endpoint):
323324
request_id = None
324325

325326
try:
@@ -328,29 +329,35 @@ def _get_server_exception(self, http_status, response_body):
328329
except (ValueError, TypeError, AttributeError):
329330
# in case the response body is not a json string, return the raw
330331
# data instead
331-
logger.warning('Failed to parse Response:%s as json format.', response_body)
332+
logger.warning('Failed to parse response as json format. Response:%s', response_body)
332333

333334
if http_status < codes.OK or http_status >= codes.MULTIPLE_CHOICES:
334335

335336
server_error_code, server_error_message = self._parse_error_info_from_response_body(
336337
response_body.decode('utf-8'))
337-
return ServerException(
338+
339+
exception = ServerException(
338340
server_error_code,
339341
server_error_message,
340342
http_status=http_status,
341343
request_id=request_id)
342344

345+
logger.error("ServerException occurred. Host:%s SDK-Version:%s ServerException:%s",
346+
endpoint, aliyunsdkcore.__version__, str(exception))
347+
348+
return exception
349+
343350
def do_action_with_exception(self, acs_request):
344351

345352
# set server response format as json, because this function will
346353
# parse the response so which format doesn't matter
347354
acs_request.set_accept_format('JSON')
348-
349355
status, headers, body, exception = self._implementation_of_do_action(acs_request)
350356

351357
if exception:
352358
raise exception
353-
359+
logger.debug('Response received. Product:%s Response-body: %s',
360+
acs_request.get_product(), body)
354361
return body
355362

356363
def _resolve_endpoint(self, request):
@@ -396,4 +403,3 @@ def set_file_logger(self, path, log_level=logging.INFO, logger_name='aliyunsdkco
396403
formatter = logging.Formatter(self.LOG_FORMAT)
397404
fh.setFormatter(formatter)
398405
log.addHandler(fh)
399-

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ 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,Attempts:%d",
65+
logger.debug("Reached the maximum number of retry. Attempts:%d",
6666
retry_policy_context.retries_attempted)
6767
return RetryCondition.NO_RETRY
6868

@@ -78,8 +78,9 @@ 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("Retryable ClientException occurred,ClientException:%s",
82-
exception, exc_info=True)
81+
82+
logger.debug("Retryable ClientException occurred. ClientException:%s",
83+
exception)
8384
return RetryCondition.SHOULD_RETRY
8485

8586
if isinstance(exception, ServerException):
@@ -88,16 +89,16 @@ def should_retry(self, retry_policy_context):
8889
request,
8990
self.retry_config)
9091
if isinstance(normal_errors, list) and error_code_ in normal_errors:
91-
logger.debug("Retryable ServerException occurred,ServerException:%s",
92-
exception, exc_info=True)
92+
logger.debug("Retryable ServerException occurred. ServerException:%s",
93+
exception)
9394
return RetryCondition.SHOULD_RETRY
9495

9596
throttling_errors = _find_data_in_retry_config("RetryableThrottlingErrors",
9697
request,
9798
self.retry_config)
9899
if isinstance(throttling_errors, list) and error_code_ in throttling_errors:
99-
logger.debug("Retryable ThrottlingError occurred,ThrottlingError:%s",
100-
exception, exc_info=True)
100+
logger.debug("Retryable ThrottlingError occurred. ThrottlingError:%s",
101+
exception)
101102
return RetryCondition.SHOULD_RETRY | \
102103
RetryCondition.SHOULD_RETRY_WITH_THROTTLING_BACKOFF
103104

@@ -119,7 +120,7 @@ def __init__(self, retryable_http_status_list=None):
119120
def should_retry(self, retry_policy_context):
120121
if retry_policy_context.http_status_code in self.retryable_http_status_list:
121122
logger.debug(
122-
"Retryable HTTP error occurred,HTTP status code: %s",
123+
"Retryable HTTP error occurred. HTTP status code: %s",
123124
retry_policy_context.http_status_code)
124125
return RetryCondition.SHOULD_RETRY
125126
else:

aliyun-python-sdk-core/aliyunsdkcore/vendored/requests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,6 @@ def emit(self, record):
7272
pass
7373

7474
logging.getLogger(__name__).addHandler(NullHandler())
75+
logging.getLogger(__name__).setLevel(logging.CRITICAL)
7576

7677

0 commit comments

Comments
 (0)