Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Blob storage SDK: Switch off logging

I have an application which is using azure.storage.blob python module.

Evidently, when I am executing it, the module is dumping its log data in the logger which I dont want because it is large and my own application info gets lost in between it.

Is there any way to remove the logger from azure.storage.blob python module?

log sample:

INFO:azure.storage.common.storageclient:Client-Request-ID=d5afebc0-aa84-11e8-be16-000d3ae070ae Outgoing request: Method=PUT, Path=/marketingcloud-raw-events/2018/8/27/bounce.csv, Query={'timeout': None}, Headers={'Content-Length': '38176', 'x-ms-blob-type': 'BlockBlob', 'x-ms-version': '2018-03-28', 'x-ms-lease-id': None, 'x-ms-client-request-id': 'd5afebc0-aa84-11e8-be16-000d3ae070ae', 'If-Match': None, 'If-Modified-Since': None, 'If-None-Match': None, 'User-Agent': 'Azure-Storage/1.3.0-1.3.1 (Python CPython 2.7.15; Linux 4.15.0-1021-azure)'

like image 969
Gagan Avatar asked Aug 28 '18 06:08

Gagan


People also ask

How to enable blob logs in Azure App service?

In there select App Service logs. Switch On Application Logging (Blob), set Level to Information, Retention Period to 1 and then click on Storage Settings. In the next window select our blob storage account and create a container.

What are the Azure SDK logs for?

This logging allows you to monitor I/O requests and responses that client libraries are making to Azure services. Typically, the logs are used to debug or diagnose communication issues. This article describes the following approaches to enable logging with the Azure SDK for .NET:

How do I enable content logging in Azure SDK?

Content logging is disabled by default. To enable it, see Log HTTP request and response bodies. The Azure SDK for .NET's client libraries log events to Event Tracing for Windows (ETW) via the System.Diagnostics.Tracing.EventSource class, which is typical for .NET.

How to enable or disable storage client logging by default?

All storage log messages are subsequently directed to the console. The following sample Java code shows how to switch storage client logging off by default by calling the static method setLoggingEnabledByDefault, and then use an OperationContext object to enable logging for a specific request:


3 Answers

This is actually very easy to do. You can adjust any logger.

Just do this near the start of your program to switch verbosity from INFO to WARNING, or whatever you prefer.

logging.getLogger("azure.storage.common.storageclient").setLevel(logging.WARNING)
like image 55
StefanGordon Avatar answered Oct 10 '22 09:10

StefanGordon


Some messages are related to http calls. Also try the following:

logger=logging.getLogger('azure.core.pipeline.policies.http_logging_policy')
logger.setLevel(logging.WARNING)
like image 31
MRTN Avatar answered Oct 10 '22 10:10

MRTN


I had the same issue that the azure blob API was spamming my log stream. When you build a BlobClient you can also pass a custom logger which you can control as you like.

logger = logging.getLogger("logger_name")
logger.disabled = True
my_blob_client = BlobClient.from_connection_string("azure blob connection string", container_name="container", blob_name="blob", logger=logger)
like image 3
EndruK Avatar answered Oct 10 '22 11:10

EndruK