diff --git a/infra/main.bicep b/infra/main.bicep index fcec59b0..6bbd3bde 100644 --- a/infra/main.bicep +++ b/infra/main.bicep @@ -1103,6 +1103,9 @@ module webSite 'modules/web-sites.bicep' = { UWSGI_THREADS:'2' APP_ENV: 'prod' AZURE_CLIENT_ID: userAssignedIdentity.outputs.clientId + // Logging Configuration + AZURE_BASIC_LOGGING_LEVEL: 'INFO' + AZURE_PACKAGE_LOGGING_LEVEL: 'WARNING' } // WAF aligned configuration for Monitoring applicationInsightResourceId: enableMonitoring ? applicationInsights!.outputs.resourceId : null diff --git a/infra/main.json b/infra/main.json index 9884931f..917017c5 100644 --- a/infra/main.json +++ b/infra/main.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "0.37.4.10188", - "templateHash": "3418531138421621433" + "templateHash": "10419838746251975414" } }, "parameters": { @@ -47243,7 +47243,9 @@ "UWSGI_PROCESSES": "2", "UWSGI_THREADS": "2", "APP_ENV": "prod", - "AZURE_CLIENT_ID": "[reference('userAssignedIdentity').outputs.clientId.value]" + "AZURE_CLIENT_ID": "[reference('userAssignedIdentity').outputs.clientId.value]", + "AZURE_BASIC_LOGGING_LEVEL": "INFO", + "AZURE_PACKAGE_LOGGING_LEVEL": "WARNING" }, "applicationInsightResourceId": "[if(parameters('enableMonitoring'), reference('applicationInsights').outputs.resourceId.value, null())]" } diff --git a/src/.env.sample b/src/.env.sample index 5bf00969..05dbe60b 100644 --- a/src/.env.sample +++ b/src/.env.sample @@ -39,4 +39,10 @@ AZURE_COSMOSDB_MONGO_VCORE_CONTENT_COLUMNS= AZURE_COSMOSDB_MONGO_VCORE_VECTOR_COLUMNS= AI_STUDIO_DRAFT_FLOW_API_KEY= AI_STUDIO_CHAT_FLOW_API_KEY= -AZURE_OPENAI_API_TYPE= \ No newline at end of file +AZURE_OPENAI_API_TYPE= + +# Logging Configuration +AZURE_BASIC_LOGGING_LEVEL=INFO +AZURE_PACKAGE_LOGGING_LEVEL=WARNING +# Optional: Comma-separated list of Azure packages to configure logging for +# AZURE_LOGGING_PACKAGES=azure.core.pipeline.policies.http_logging_policy,azure.identity.aio._internal,azure.monitor.opentelemetry.exporter.export._base \ No newline at end of file diff --git a/src/app.py b/src/app.py index 81457aee..8897a26a 100644 --- a/src/app.py +++ b/src/app.py @@ -36,6 +36,24 @@ def assets(path): if DEBUG_LOGGING: logging.basicConfig(level=logging.DEBUG) +# Logging configuration from environment variables +AZURE_BASIC_LOGGING_LEVEL = os.environ.get("AZURE_BASIC_LOGGING_LEVEL", "INFO") +AZURE_PACKAGE_LOGGING_LEVEL = os.environ.get("AZURE_PACKAGE_LOGGING_LEVEL", "WARNING") +AZURE_LOGGING_PACKAGES = os.environ.get("AZURE_LOGGING_PACKAGES", "").split(",") +AZURE_LOGGING_PACKAGES = [pkg.strip() for pkg in AZURE_LOGGING_PACKAGES if pkg.strip()] + +# Configure logging levels from environment variables +logging.basicConfig( + level=getattr(logging, AZURE_BASIC_LOGGING_LEVEL.upper(), logging.INFO) +) + +# Configure Azure package logging levels only if packages are specified +azure_level = getattr( + logging, AZURE_PACKAGE_LOGGING_LEVEL.upper(), logging.WARNING +) +for logger_name in AZURE_LOGGING_PACKAGES: + logging.getLogger(logger_name).setLevel(azure_level) + # On Your Data Settings DATASOURCE_TYPE = os.environ.get("DATASOURCE_TYPE", "AzureCognitiveSearch") SEARCH_TOP_K = os.environ.get("SEARCH_TOP_K", 5)