Skip to content

Commit 2e65cec

Browse files
Merge pull request #649 from microsoft/PSL-US-26408
feat: Implementation of Configurable Logging Control via Flag
2 parents e6803d2 + f498347 commit 2e65cec

File tree

10 files changed

+109
-126
lines changed

10 files changed

+109
-126
lines changed

infra/main.bicep

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,6 @@ var dnsZoneIndex = {
460460
sqlServer: 9
461461
search: 10
462462
}
463-
// List of DNS zone indices that correspond to AI-related services.
464-
var aiRelatedDnsZoneIndices = [
465-
dnsZoneIndex.cognitiveServices
466-
dnsZoneIndex.openAI
467-
dnsZoneIndex.aiServices
468-
]
469463

470464
// ===================================================
471465
// DEPLOY PRIVATE DNS ZONES
@@ -1575,6 +1569,9 @@ module webSiteBackend 'modules/web-sites.bicep' = {
15751569
SOLUTION_NAME: solutionSuffix
15761570
APP_ENV: 'Prod'
15771571
AZURE_CLIENT_ID: backendUserAssignedIdentity.outputs.clientId
1572+
AZURE_BASIC_LOGGING_LEVEL: 'INFO'
1573+
AZURE_PACKAGE_LOGGING_LEVEL: 'WARNING'
1574+
AZURE_LOGGING_PACKAGES: ''
15781575
}
15791576
// WAF aligned configuration for Monitoring
15801577
applicationInsightResourceId: enableMonitoring ? applicationInsights!.outputs.resourceId : null

infra/main.json

Lines changed: 76 additions & 78 deletions
Large diffs are not rendered by default.

src/api/.env.sample

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ SQLDB_DATABASE=
2424
SQLDB_SERVER=
2525
USE_CHAT_HISTORY_ENABLED="True"
2626
APP_ENV="dev"
27+
# Basic application logging (default: INFO level)
28+
AZURE_BASIC_LOGGING_LEVEL=INFO
29+
# Azure package logging (default: WARNING level to suppress INFO)
30+
AZURE_PACKAGE_LOGGING_LEVEL=WARNING
31+
# Comma-separated list of specific logger names to configure (default: empty - no custom loggers)
32+
# Example: AZURE_LOGGING_PACKAGES=azure.identity.aio._internal,azure.monitor.opentelemetry.exporter.export._base
33+
AZURE_LOGGING_PACKAGES=

src/api/api/api_routes.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
router = APIRouter()
2020

21-
# Configure logging
22-
logging.basicConfig(level=logging.INFO)
2321
logger = logging.getLogger(__name__)
2422

2523
# Check if the Application Insights Instrumentation Key is set in the environment variables
@@ -32,20 +30,6 @@
3230
# Log a warning if the Instrumentation Key is not found
3331
logging.warning("No Application Insights Instrumentation Key found. Skipping configuration")
3432

35-
# Configure logging
36-
logging.basicConfig(level=logging.INFO)
37-
38-
# Suppress INFO logs from 'azure.core.pipeline.policies.http_logging_policy'
39-
logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(
40-
logging.WARNING
41-
)
42-
logging.getLogger("azure.identity.aio._internal").setLevel(logging.WARNING)
43-
44-
# Suppress info logs from OpenTelemetry exporter
45-
logging.getLogger("azure.monitor.opentelemetry.exporter.export._base").setLevel(
46-
logging.WARNING
47-
)
48-
4933

5034
@router.get("/fetchChartData")
5135
async def fetch_chart_data():

src/api/api/history_routes.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
router = APIRouter()
1313

14-
# Configure logging
15-
logging.basicConfig(level=logging.INFO)
1614
logger = logging.getLogger(__name__)
1715

1816
# Check if the Application Insights Instrumentation Key is set in the environment variables
@@ -25,20 +23,6 @@
2523
# Log a warning if the Instrumentation Key is not found
2624
logging.warning("No Application Insights Instrumentation Key found. Skipping configuration")
2725

28-
# Configure logging
29-
logging.basicConfig(level=logging.INFO)
30-
31-
# Suppress INFO logs from 'azure.core.pipeline.policies.http_logging_policy'
32-
logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(
33-
logging.WARNING
34-
)
35-
logging.getLogger("azure.identity.aio._internal").setLevel(logging.WARNING)
36-
37-
# Suppress info logs from OpenTelemetry exporter
38-
logging.getLogger("azure.monitor.opentelemetry.exporter.export._base").setLevel(
39-
logging.WARNING
40-
)
41-
4226
# Single instance of HistoryService (if applicable)
4327
history_service = HistoryService()
4428

src/api/app.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"""
88

99

10+
import logging
11+
import os
1012
from contextlib import asynccontextmanager
1113
from fastapi import FastAPI
1214
from fastapi.middleware.cors import CORSMiddleware
@@ -21,8 +23,29 @@
2123
from api.api_routes import router as backend_router
2224
from api.history_routes import router as history_router
2325

26+
# Load environment variables
2427
load_dotenv()
2528

29+
# Configure logging
30+
# Basic application logging (default: INFO level)
31+
AZURE_BASIC_LOGGING_LEVEL = os.getenv("AZURE_BASIC_LOGGING_LEVEL", "INFO").upper()
32+
# Azure package logging (default: WARNING level to suppress INFO)
33+
AZURE_PACKAGE_LOGGING_LEVEL = os.getenv("AZURE_PACKAGE_LOGGING_LEVEL", "WARNING").upper()
34+
# Azure logging packages (default: empty list)
35+
AZURE_LOGGING_PACKAGES = [
36+
pkg.strip() for pkg in os.getenv("AZURE_LOGGING_PACKAGES", "").split(",") if pkg.strip()
37+
]
38+
39+
# Basic config: logging.basicConfig(level=logging.INFO)
40+
logging.basicConfig(
41+
level=getattr(logging, AZURE_BASIC_LOGGING_LEVEL, logging.INFO),
42+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
43+
)
44+
45+
# Package config: Azure loggers set to WARNING to suppress INFO
46+
for logger_name in AZURE_LOGGING_PACKAGES:
47+
logging.getLogger(logger_name).setLevel(getattr(logging, AZURE_PACKAGE_LOGGING_LEVEL, logging.WARNING))
48+
2649

2750
@asynccontextmanager
2851
async def lifespan(fastapi_app: FastAPI):

src/api/helpers/utils.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55

66
import requests
77

8-
DEBUG = os.environ.get("DEBUG", "false")
9-
if DEBUG.lower() == "true":
10-
logging.basicConfig(level=logging.DEBUG)
11-
128
AZURE_SEARCH_PERMITTED_GROUPS_COLUMN = os.environ.get(
139
"AZURE_SEARCH_PERMITTED_GROUPS_COLUMN"
1410
)

src/api/services/chart_service.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
from api.models.input_models import ChartFilters
55
from common.database.sqldb_service import adjust_processed_data_dates, fetch_chart_data, fetch_filters_data
66

7-
# Configure logging
8-
logging.basicConfig(level=logging.INFO)
97
logger = logging.getLogger(__name__)
108

119

src/api/services/chat_service.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
HOST_NAME = "CKM"
2929
HOST_INSTRUCTIONS = "Answer questions about call center operations"
3030

31-
# Configure logging
32-
logging.basicConfig(level=logging.INFO)
3331
logger = logging.getLogger(__name__)
3432

3533

src/api/services/history_service.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from common.database.cosmosdb_service import CosmosConversationClient
99
from helpers.azure_credential_utils import get_azure_credential
1010

11-
# Configure logging
12-
logging.basicConfig(level=logging.INFO)
1311
logger = logging.getLogger(__name__)
1412

1513

0 commit comments

Comments
 (0)