Skip to content

Commit e8b9cc0

Browse files
Implementation of Configurable Logging Control via Flag
1 parent 331bd04 commit e8b9cc0

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

infra/main.bicep

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,8 @@ module webSite 'modules/web-sites.bicep' = {
11221122
AZURE_SEARCH_STRICTNESS: azureSearchStrictness
11231123
AZURE_OPENAI_EMBEDDING_NAME: embeddingModel
11241124
AZURE_OPENAI_EMBEDDING_ENDPOINT : aiFoundryAiServices.outputs.endpoint
1125+
AZURE_BASIC_LOGGING_LEVEL: 'INFO'
1126+
AZURE_PACKAGE_LOGGING_LEVEL: 'WARNING'
11251127
SQLDB_SERVER: sqlServerFqdn
11261128
SQLDB_DATABASE: sqlDbName
11271129
USE_INTERNAL_STREAM: useInternalStream

src/App/.env.sample

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ AZURE_OPENAI_ENDPOINT=
1212
AZURE_OPENAI_EMBEDDING_NAME="text-embedding-ada-002"
1313
AZURE_OPENAI_EMBEDDING_ENDPOINT=
1414

15+
# Logging settings
16+
AZURE_BASIC_LOGGING_LEVEL="INFO"
17+
AZURE_PACKAGE_LOGGING_LEVEL="WARNING"
18+
# AZURE_LOGGING_PACKAGES="azure.core.pipeline.policies.http_logging_policy,azure.identity.aio._internal,azure.monitor.opentelemetry.exporter.export._base"
19+
1520
# User Interface
1621
UI_TITLE=
1722
UI_LOGO=

src/App/app.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,23 @@
5656
)
5757

5858
# Configure logging
59-
logging.basicConfig(level=logging.INFO)
59+
basic_level = getattr(
60+
logging, config.AZURE_BASIC_LOGGING_LEVEL.upper(), logging.INFO
61+
)
62+
logging.basicConfig(level=basic_level)
6063

61-
# Suppress INFO logs from 'azure.core.pipeline.policies.http_logging_policy'
62-
logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(
63-
logging.WARNING
64+
# Configure Azure package logging levels
65+
azure_packages_env = os.environ.get("AZURE_LOGGING_PACKAGES")
66+
azure_packages = (
67+
[pkg.strip() for pkg in azure_packages_env.split(',')]
68+
if azure_packages_env else []
6469
)
65-
logging.getLogger("azure.identity.aio._internal").setLevel(logging.WARNING)
6670

67-
# Suppress info logs from OpenTelemetry exporter
68-
logging.getLogger("azure.monitor.opentelemetry.exporter.export._base").setLevel(
69-
logging.WARNING
71+
package_level = getattr(
72+
logging, config.AZURE_PACKAGE_LOGGING_LEVEL.upper(), logging.WARNING
7073
)
74+
for package in azure_packages:
75+
logging.getLogger(package).setLevel(package_level)
7176

7277

7378
def create_app():

src/App/backend/common/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ def __init__(self):
3535
"APPLICATIONINSIGHTS_CONNECTION_STRING"
3636
)
3737

38+
# Azure Logging Configuration
39+
self.AZURE_BASIC_LOGGING_LEVEL = os.environ.get(
40+
"AZURE_BASIC_LOGGING_LEVEL", "INFO"
41+
)
42+
self.AZURE_PACKAGE_LOGGING_LEVEL = os.environ.get(
43+
"AZURE_PACKAGE_LOGGING_LEVEL", "WARNING"
44+
)
45+
3846
self.DEBUG = os.environ.get("DEBUG", "false")
3947

4048
# Current minimum Azure OpenAI version supported

0 commit comments

Comments
 (0)