Install & Compatibility
Where this runs
tested against v1.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.496s · 23.3MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 4.3s · import 0.474s · 24MB
22MB installed
● package 22MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
AzureLogServiceHandler
✓ from logging_azure.handler import AzureLogServiceHandler
This quickstart demonstrates how to configure the `logging-azure-rest` handler using Python's `logging.config.dictConfig`. It sets up a logger that outputs to the console and sends INFO, WARNING, and ERROR level messages to Azure Log Analytics. Ensure `AZURE_LOG_CUSTOMER_ID`, `AZURE_LOG_SHARED_KEY`, and `AZURE_LOG_DEFAULT_NAME` environment variables are set with your Azure Log Workspace details. The `AZURE_LOG_DEFAULT_NAME` will appear as 'MyPythonAppLogs_CL' (or whatever you set) in Azure.
import logging
import logging.config
import os
import time
# Set required environment variables for the handler
os.environ['AZURE_LOG_CUSTOMER_ID'] = os.environ.get('AZURE_LOG_CUSTOMER_ID', 'YOUR_AZURE_LOG_CUSTOMER_ID')
os.environ['AZURE_LOG_SHARED_KEY'] = os.environ.get('AZURE_LOG_SHARED_KEY', 'YOUR_AZURE_LOG_SHARED_KEY')
os.environ['AZURE_LOG_DEFAULT_NAME'] = os.environ.get('AZURE_LOG_DEFAULT_NAME', 'MyPythonAppLogs')
LOGGING_CONFIG = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'azure': {
'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
},
'default': {
'format': '%(levelname)s:%(name)s:%(message)s'
}
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'default'
},
'azure_log_oms': {
'level': 'INFO',
'class': 'logging_azure.handler.AzureLogServiceHandler',
'formatter': 'azure'
}
},
'loggers': {
'my_app': {
'handlers': ['console', 'azure_log_oms'],
'level': 'INFO',
'propagate': False
},
'': {
'handlers': ['console'],
'level': 'WARNING',
'propagate': True
}
},
'root': {
'handlers': ['console'],
'level': 'WARNING'
}
}
logging.config.dictConfig(LOGGING_CONFIG)
logger = logging.getLogger('my_app')
logger.info('This is an informational message sent to Azure Log Analytics.')
logger.warning('This is a warning message. Take action!')
logger.error('An error occurred in the application.')
print("Logs sent. Check your Azure Log Analytics workspace (table: MyPythonAppLogs_CL).")
print("Note: Logs may take up to 30 minutes to appear initially in Azure.")
# Give the background thread some time to send logs before exiting
time.sleep(10)
Debug
Known issues
breakingThe Azure Monitor Logs Ingestion API will enforce TLS 1.2 or higher connections starting March 1, 2026. Ensure your Python environment supports and uses TLS 1.2+ for connections to Azure. Older Python versions or configurations might fail after this date.fixUpgrade Python to a version that supports modern TLS (Python 3.7+ usually suffices, ensure OpenSSL is updated) and verify network configurations do not restrict TLS versions.
affects: All versions interacting with Azure Monitor Logs Ingestion API after 2026-03-01
gotchaThree environment variables are required for the handler to function: `AZURE_LOG_CUSTOMER_ID` (your Log Analytics workspace ID), `AZURE_LOG_SHARED_KEY` (one of your workspace keys), and `AZURE_LOG_DEFAULT_NAME` (the base name for your custom log table). If these are not set, the handler will not send logs.fixSet `AZURE_LOG_CUSTOMER_ID`, `AZURE_LOG_SHARED_KEY`, and `AZURE_LOG_DEFAULT_NAME` environment variables before initializing the logger.
affects: All versions
gotchaThe `AZURE_LOG_DEFAULT_NAME` you specify for your custom logs will automatically be suffixed with `_CL` within the Azure Log Workspace (e.g., 'MyPythonAppLogs' becomes 'MyPythonAppLogs_CL'). Remember this suffix when querying your logs in Azure Log Analytics.fixAlways append `_CL` to your custom log table name when performing queries in Azure Log Analytics (e.g., `MyPythonAppLogs_CL | ...`).
affects: All versions
gotchaSending verbose logs (e.g., `logging.DEBUG`) to Azure Log Workspace can incur significant costs due to data ingestion fees. It is strongly recommended to set an appropriate log level (e.g., `INFO`, `WARNING`, `ERROR`) for your Azure handler to avoid unnecessary costs, especially in production.fixConfigure your `AzureLogServiceHandler` with a suitable `level` (e.g., `logging.INFO` or higher) and ensure specific loggers do not propagate `DEBUG` messages to it in production environments.
affects: All versions
gotchaCustom logs sent to Azure Log Analytics via the REST API can experience an initial delay of up to 30 minutes before they first appear in the workspace. Subsequent logs typically appear within minutes.fixBe patient when first setting up and sending custom logs; check back after 30 minutes if logs are not immediately visible. For ongoing logging, expect a few minutes of latency.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'logging_azure'
The `logging-azure-rest` Python package, or its `logging_azure` module, is not installed or not accessible in the current Python environment.
fixEnsure the package is installed using pip: `pip install logging-azure-rest`
AuthenticationFailed: The access token is invalid.
The Azure Log Workspace Customer ID (`AZURE_LOG_CUSTOMER_ID`) or Shared Key (`AZURE_LOG_SHARED_KEY`) environment variables are incorrect, expired, or the associated service principal lacks the necessary permissions to ingest logs into the Azure Log Workspace via the REST API.
fixVerify that the `AZURE_LOG_CUSTOMER_ID` and `AZURE_LOG_SHARED_KEY` environment variables are correctly set with valid credentials from your Azure Log Analytics Workspace. Additionally, ensure the associated identity has 'Log Analytics Contributor' role or equivalent permissions on the Log Analytics Workspace.
Logs not appearing in Azure Log Workspace
Even if the application logs without Python errors, logs might not appear in Azure due to an incorrect 'log type' name (`AZURE_LOG_DEFAULT_NAME`), a mismatch between the log schema sent and the expected schema in Azure, or issues with the Azure Data Collection Rule (if applicable).
fixCheck the `AZURE_LOG_DEFAULT_NAME` environment variable for typos. Confirm the log schema being sent by the application matches the custom table schema in Azure Log Workspace. Utilize Azure Monitor's 'Logs' section to query the `Operation` table or check diagnostic settings for ingestion errors related to your Data Collection Rule or Log Analytics Workspace.
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: ...
The request to the Azure Log Workspace REST API was denied because the authenticated identity (based on `AZURE_LOG_CUSTOMER_ID` and `AZURE_LOG_SHARED_KEY`) does not have sufficient permissions to perform the log ingestion operation on the specified workspace or log type.
fixVerify that the shared key and customer ID are correct and have not been revoked. Ensure the service principal or managed identity associated with the provided credentials has at least 'Log Analytics Contributor' role on the target Azure Log Analytics Workspace.
Upgrade
Version history
1.3.0latest on PyPI · released Jun 14, 2021
Audit
Dependencies
requestsrequiredUsed for making HTTP requests to the Azure Log Workspace REST API.
pytzrequiredUsed for timezone handling.