Skip to content

Commit

Permalink
Suppress extraneous INFO level logging by azure-identity
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Baumann committed Jan 19, 2023
1 parent 6b5fdd5 commit d6d42d7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions terra_notebook_utils/azure_auth.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""
Microsoft Azure specific code.
Currently limited to Azure auth.
Microsoft Azure identity/auth support.
See:
https://azuresdkdocs.blob.core.windows.net/$web/python/azure-identity/1.12.0/index.html
https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python
https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/azure/identity/_credentials/default.py
"""

import logging
import os
from typing import Optional

Expand All @@ -24,6 +23,19 @@
_AZURE_CREDENTIAL: Optional[DefaultAzureCredential] = None


def _set_azure_identity_logging_level(level) -> None:
""" Set the logging level for modules participating the Azure default credential flow """
import azure.identity
logging.getLogger(azure.identity._credentials.environment.__name__).setLevel(level)
logging.getLogger(azure.identity._credentials.managed_identity.__name__).setLevel(level)
logging.getLogger(azure.identity._credentials.chained.__name__).setLevel(level)
logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(level)


# Suppress extraneous azure-identity INFO level logging
_set_azure_identity_logging_level(logging.WARNING)


def _get_default_credential() -> DefaultAzureCredential:
"""
Instantiate DefaultAzureCredential lazily if/when needed.
Expand Down

0 comments on commit d6d42d7

Please sign in to comment.