Skip to content

Commit cf940c7

Browse files
feat: Implementation of Configurable Logging Control via Flag (#757)
* Implementation of Configurable Logging Control via Flag * lint issue fix * lint issue fix
1 parent da725a6 commit cf940c7

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

infra/main.bicep

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,9 @@ module webSite 'modules/web-sites.bicep' = {
11031103
UWSGI_THREADS:'2'
11041104
APP_ENV: 'prod'
11051105
AZURE_CLIENT_ID: userAssignedIdentity.outputs.clientId
1106+
// Logging Configuration
1107+
AZURE_BASIC_LOGGING_LEVEL: 'INFO'
1108+
AZURE_PACKAGE_LOGGING_LEVEL: 'WARNING'
11061109
}
11071110
// WAF aligned configuration for Monitoring
11081111
applicationInsightResourceId: enableMonitoring ? applicationInsights!.outputs.resourceId : null

infra/main.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"_generator": {
77
"name": "bicep",
88
"version": "0.37.4.10188",
9-
"templateHash": "3418531138421621433"
9+
"templateHash": "10419838746251975414"
1010
}
1111
},
1212
"parameters": {
@@ -47243,7 +47243,9 @@
4724347243
"UWSGI_PROCESSES": "2",
4724447244
"UWSGI_THREADS": "2",
4724547245
"APP_ENV": "prod",
47246-
"AZURE_CLIENT_ID": "[reference('userAssignedIdentity').outputs.clientId.value]"
47246+
"AZURE_CLIENT_ID": "[reference('userAssignedIdentity').outputs.clientId.value]",
47247+
"AZURE_BASIC_LOGGING_LEVEL": "INFO",
47248+
"AZURE_PACKAGE_LOGGING_LEVEL": "WARNING"
4724747249
},
4724847250
"applicationInsightResourceId": "[if(parameters('enableMonitoring'), reference('applicationInsights').outputs.resourceId.value, null())]"
4724947251
}

src/.env.sample

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,10 @@ AZURE_COSMOSDB_MONGO_VCORE_CONTENT_COLUMNS=
3939
AZURE_COSMOSDB_MONGO_VCORE_VECTOR_COLUMNS=
4040
AI_STUDIO_DRAFT_FLOW_API_KEY=
4141
AI_STUDIO_CHAT_FLOW_API_KEY=
42-
AZURE_OPENAI_API_TYPE=
42+
AZURE_OPENAI_API_TYPE=
43+
44+
# Logging Configuration
45+
AZURE_BASIC_LOGGING_LEVEL=INFO
46+
AZURE_PACKAGE_LOGGING_LEVEL=WARNING
47+
# Optional: Comma-separated list of Azure packages to configure logging for
48+
# AZURE_LOGGING_PACKAGES=azure.core.pipeline.policies.http_logging_policy,azure.identity.aio._internal,azure.monitor.opentelemetry.exporter.export._base

src/app.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ def assets(path):
3636
if DEBUG_LOGGING:
3737
logging.basicConfig(level=logging.DEBUG)
3838

39+
# Logging configuration from environment variables
40+
AZURE_BASIC_LOGGING_LEVEL = os.environ.get("AZURE_BASIC_LOGGING_LEVEL", "INFO")
41+
AZURE_PACKAGE_LOGGING_LEVEL = os.environ.get("AZURE_PACKAGE_LOGGING_LEVEL", "WARNING")
42+
AZURE_LOGGING_PACKAGES = os.environ.get("AZURE_LOGGING_PACKAGES", "").split(",")
43+
AZURE_LOGGING_PACKAGES = [pkg.strip() for pkg in AZURE_LOGGING_PACKAGES if pkg.strip()]
44+
45+
# Configure logging levels from environment variables
46+
logging.basicConfig(
47+
level=getattr(logging, AZURE_BASIC_LOGGING_LEVEL.upper(), logging.INFO)
48+
)
49+
50+
# Configure Azure package logging levels only if packages are specified
51+
azure_level = getattr(
52+
logging, AZURE_PACKAGE_LOGGING_LEVEL.upper(), logging.WARNING
53+
)
54+
for logger_name in AZURE_LOGGING_PACKAGES:
55+
logging.getLogger(logger_name).setLevel(azure_level)
56+
3957
# On Your Data Settings
4058
DATASOURCE_TYPE = os.environ.get("DATASOURCE_TYPE", "AzureCognitiveSearch")
4159
SEARCH_TOP_K = os.environ.get("SEARCH_TOP_K", 5)

0 commit comments

Comments
 (0)