'Suppress printing of response from Azure Queue Storage

When I send a message to a queue I want the response returned into an object which I can then include in my log or not. However for some reason when I execute the following code:

from azure.storage.queue import QueueClient, TextBase64EncodePolicy
# ... some code running ##########################
            queue = QueueClient.from_connection_string(conn_str=conn_queue, queue_name="items",
                                                   message_encode_policy=TextBase64EncodePolicy())
# ... some message generated #####################
response=queue.send_message(json.dumps(item_dict))

a complete message is printed to my log. It looks for example like this:

Request URL: 'https://{some_storage_account}.queue.core.windows.net/items/messages'
Request method: 'POST'
Request headers: 'Accept': 'application/xml'
'Content-Type': 'application/xml; charset=utf-8'
'x-ms-version': 'REDACTED'
'Content-Length': '1295'
'x-ms-date': 'REDACTED'
'x-ms-client-request-id': '3452464c-06b2-11eb-9f96-00155d6ebdc5'
'User-Agent': 'azsdk-python-storage-queue/12.1.3 Python/3.8.5 (Linux-4.19.104-microsoft-standard-x86_64-with-glibc2.2.5)'
'Authorization': 'REDACTED'
A body is sent with the request
Response status: 201
Response headers:
'Transfer-Encoding': 'chunked'
'Content-Type': 'application/xml'
'Server': 'Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0'
'x-ms-request-id': '1720a5da-c003-002b-18be-9ab4d4000000'
'x-ms-version': 'REDACTED'
'Date': 'Mon, 05 Oct 2020 02:26:41 GMT'

How can I prevent this gulp of information to be printed to my log?

I have spent at least half an hour on the docs from microsoft. But I can't find where I can turn this behaviour off.



Solution 1:[1]

I tried with the logging-levels - it does not do the trick for me. However when I define a new logger for this connection then it works:

queue_logger = logging.getLogger("logger_name")
# queue_logger.disabled = True
queue_logger.setLevel(logging.DEBUG)
queue = QueueClient.from_connection_string(conn_str=conn_queue, queue_name="debug",message_encode_policy=TextBase64EncodePolicy(), logger=queue_logger)

Ultimately I feel like I should use the REST API instead of the Python Azure SDK for this. REST API allows me to log-output based on the response status. For some weird reason the SDK does not offer me this possibility.

Solution 2:[2]

The answer should be here, in the README of azure-storage-python in GitHub:

Here is how we use the logging levels, it is recommended to use INFO:

DEBUG: log strings to sign
INFO: log outgoing requests and responses, as well as retry attempts  # <--
WARNING: not used
ERROR: log calls that still failed after all the retries

This should do it, as recommended by Kalies LAMIRI (I didn't try myself):

logger = logging.getLogger("azure.storage")
logger.setLevel(logging.ERROR)

Solution 3:[3]

logger = logging.getLogger("azure.core.pipeline.policies.http_logging_policy")
logger.setLevel(logging.WARNING)

This Worked For Me - Add this to your code

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 5th
Solution 2 Roberto Prevato
Solution 3 raj