Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 禁止从Azure队列存储打印响应_Python_Python 3.x_Azure Storage Queues - Fatal编程技术网

Python 禁止从Azure队列存储打印响应

Python 禁止从Azure队列存储打印响应,python,python-3.x,azure-storage-queues,Python,Python 3.x,Azure Storage Queues,当我向队列发送消息时,我希望将响应返回到一个对象中,然后我可以将该对象包含在日志中,也可以不包含在日志中。但是,由于某些原因,当我执行以下代码时: from azure.storage.queue import QueueClient, TextBase64EncodePolicy # ... some code running ########################## queue = QueueClient.from_connection_string(co

当我向队列发送消息时,我希望将响应返回到一个对象中,然后我可以将该对象包含在日志中,也可以不包含在日志中。但是,由于某些原因,当我执行以下代码时:

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))
完整的消息将打印到我的日志中。例如,它看起来像这样:

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'
我怎样才能防止这些信息被打印到我的日志中


我在这条路上至少花了半个小时。但是我找不到在哪里可以关闭这种行为。

答案应该在这里,在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

我尝试了日志记录级别-它对我来说不起作用。但是,当我为此连接定义一个新的记录器时,它会工作:

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)

最终,我觉得应该使用RESTAPI而不是Python Azure SDK来实现这一点。RESTAPI允许我根据响应状态记录输出。出于某种奇怪的原因,SDK没有为我提供这种可能性。

尝试为您的应用程序创建一个特定的记录器,并将azur模块日志记录模式设置为更高的值(>警告),我尝试过。直到我将此调试器包含到我的
QueueClient
中,我才开始工作。很抱歉,我的回答没有帮助。几个月前我使用了那个SDK,当时它足以配置记录器级别。感谢分享解决方案。
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)