How to change the log level of Azure SDK for Python

Introduction

I wanted to persist the data of Azure App Service with CosmosDB, so I added the ʻazure-cosmos` library with pip and implemented the connection process.

requirements.txt


azure-cosmos==4.0.0

After implementation, when debugging, I noticed a lot of logs about the Azure SDK package ʻazure.core.pipeline.policies.http_logging_policy`.

In this article, I will show you how to suppress the log output by changing the log level of the above logger.

Log output example

In my environment, the following log was output.

2020-06-24 19:11:55,493 DEBUG urllib3.connectionpool :https://xxx.documents.azure.com:443 "POST /dbs/xxx/colls/xxx/docs/ HTTP/1.1" 200 None
2020-06-24 19:11:55,495 INFO azure.core.pipeline.policies.http_logging_policy :Response status: 200
2020-06-24 19:11:55,495 INFO azure.core.pipeline.policies.http_logging_policy :Response headers:
2020-06-24 19:11:55,495 INFO azure.core.pipeline.policies.http_logging_policy :    'Cache-Control': 'no-store, no-cache'
2020-06-24 19:11:55,495 INFO azure.core.pipeline.policies.http_logging_policy :    'Pragma': 'no-cache'
2020-06-24 19:11:55,495 INFO azure.core.pipeline.policies.http_logging_policy :    'Transfer-Encoding': 'chunked'
2020-06-24 19:11:55,495 INFO azure.core.pipeline.policies.http_logging_policy :    'Content-Type': 'application/json'
2020-06-24 19:11:55,495 INFO azure.core.pipeline.policies.http_logging_policy :    'Server': 'Microsoft-HTTPAPI/2.0'
2020-06-24 19:11:55,496 INFO azure.core.pipeline.policies.http_logging_policy :    'Strict-Transport-Security': 'REDACTED'
2020-06-24 19:11:55,496 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-last-state-change-utc': 'REDACTED'
2020-06-24 19:11:55,496 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-resource-quota': 'REDACTED'
2020-06-24 19:11:55,496 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-resource-usage': 'REDACTED'
2020-06-24 19:11:55,496 INFO azure.core.pipeline.policies.http_logging_policy :    'lsn': 'REDACTED'
2020-06-24 19:11:55,496 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-item-count': 'REDACTED'
2020-06-24 19:11:55,496 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-schemaversion': 'REDACTED'
2020-06-24 19:11:55,496 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-alt-content-path': 'REDACTED'
2020-06-24 19:11:55,496 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-content-path': 'REDACTED'
2020-06-24 19:11:55,496 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-quorum-acked-lsn': 'REDACTED'
2020-06-24 19:11:55,496 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-current-write-quorum': 'REDACTED'
2020-06-24 19:11:55,496 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-current-replica-set-size': 'REDACTED'
2020-06-24 19:11:55,496 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-xp-role': 'REDACTED'
2020-06-24 19:11:55,497 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-cosmos-query-execution-info': 'REDACTED'
2020-06-24 19:11:55,497 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-global-Committed-lsn': 'REDACTED'
2020-06-24 19:11:55,497 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-number-of-read-regions': 'REDACTED'
2020-06-24 19:11:55,497 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-transport-request-id': 'REDACTED'
2020-06-24 19:11:55,497 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-cosmos-llsn': 'REDACTED'
2020-06-24 19:11:55,497 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-cosmos-quorum-acked-llsn': 'REDACTED'
2020-06-24 19:11:55,497 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-session-token': 'REDACTED'
2020-06-24 19:11:55,498 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-request-charge': 'REDACTED'
2020-06-24 19:11:55,498 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-serviceversion': 'REDACTED'
2020-06-24 19:11:55,498 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-activity-id': 'REDACTED'
2020-06-24 19:11:55,498 INFO azure.core.pipeline.policies.http_logging_policy :    'x-ms-gatewayversion': 'REDACTED'
2020-06-24 19:11:55,498 INFO azure.core.pipeline.policies.http_logging_policy :    'Date': 'Wed, 24 Jun 2020 10:11:55 GMT'

Workaround

ʻAzure.core.pipeline.policies.http_logging_policy` You can suppress unnecessary logs by setting the log level in the logger.

application.py


logging.getLogger('azure.core.pipeline.policies.http_logging_policy').setLevel('WARNING')

In this example, logs of log level WARNING or higher are output. If you want to set other logging levels, see logging — Logging facility for Python — Python 3.8.3 documentation (https://docs.python.org/3.8/library/logging.html#levels). ..

reference

-[Quick Start: Build Python Apps Using Azure Cosmos DB SQL API Account | Microsoft Docs](https://docs.microsoft.com/en-us/azure/cosmos-db/create-sql-api -python)

Recommended Posts

How to change the log level of Azure SDK for Python
[Python] How to change the date format (display format)
Upgrade the Azure Machine Learning SDK for Python
How to get the number of digits in Python
[Python] Summary of how to specify the color of the figure
How to change Python version
[Introduction to Python] How to get the index of data with a for statement
Check! How to use Azure Key Vault with Azure SDK for Python! (Measures around authentication)
[Note] The story of setting up the SDK for Python of Azure IoT Hub on Linux
[Python] Change the Cache-Control of the object uploaded to Cloud Storage
[python] How to use the library Matplotlib for drawing graphs
[Hyperledger Iroha] Notes on how to use the Python SDK
How to specify Cache-Control for blob storage in Azure Storage in Python
I didn't know how to use the [python] for statement
How to get the Python version
Change the Python version of Homebrew
[Python] How to import the library
Add TRACE log level to Python ...?
[Python] Change the alphabet to numbers
How to change python version of Notebook in Watson Studio (or Cloud Pak for Data)
How to determine the existence of a selenium element in Python
How to know the internal structure of an object in Python
How to change the color of just the button pressed in Tkinter
How to check the memory size of a variable in Python
[Python] How to get the first and last days of the month
How to configure CORS settings for Azure storage service in Python
Feel free to change the label of the legend in Seaborn in python
[Introduction to Python] How to use the in operator in a for statement?
How to check the memory size of a dictionary in Python
How to use machine learning for work? 01_ Understand the purpose of machine learning
I summarized how to change the boot parameters of GRUB and GRUB2
How to update the python version of Cloud Shell on GCP
[Python] Summary of how to use pandas
Change the length of Python csv strings
Script to change the description of fasta
How to check the version of Django
[Python] Organizing how to use for statements
[Python2.7] Summary of how to use unittest
Pandas of the beginner, by the beginner, for the beginner [Python]
How to use "deque" for Python data
Summary of how to use Python list
[Python2.7] Summary of how to use subprocess
[Python] How to use the for statement. A method of extracting by specifying a range or conditions.
[Question] How to use plot_surface of python
[Python] How to specify the window display position and size of matplotlib
How to crop the lower right part of the image with Python OpenCV
[Python] How to change character string (str) data to date (strptime of datetime)
Python> sys.path> List of strings indicating the path to search for modules
[Introduction to Python] How to sort the contents of a list efficiently with list sort
How to calculate the volatility of a brand
How to use the C library in Python
The fastest way for beginners to master Python
How to specify the launch browser for JupyterLab 3.0.0
How to find the area of the Voronoi diagram
[Python] How to use two types of type ()
Setting to output the log of cron execution
The inaccuracy of Tensorflow was due to log (0)
Summary of how to import files in Python 3
How to install Python for pharmaceutical company researchers
Summary of how to use MNIST in Python
Change the decimal point of logging from, to.