Skip to content

Commit ee6ee18

Browse files
added logger with config
1 parent 08f528a commit ee6ee18

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

src/backend/.env.sample

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ AZURE_AI_SEARCH_INDEX_NAME=
3333
AZURE_AI_SEARCH_ENDPOINT=
3434
AZURE_AI_SEARCH_API_KEY=
3535
BING_CONNECTION_NAME=
36+
37+
# Basic application logging (default: INFO level)
38+
AZURE_BASIC_LOGGING_LEVEL=INFO
39+
# Azure package logging (default: WARNING level to suppress INFO)
40+
AZURE_PACKAGE_LOGGING_LEVEL=WARNING

src/backend/app_kernel.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,19 @@ async def lifespan(app: FastAPI):
6060
"No Application Insights Instrumentation Key found. Skipping configuration"
6161
)
6262

63-
# Configure logging
64-
logging.basicConfig(level=logging.INFO)
65-
66-
# Suppress INFO logs from 'azure.core.pipeline.policies.http_logging_policy'
67-
logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(
68-
logging.WARNING
69-
)
70-
logging.getLogger("azure.identity.aio._internal").setLevel(logging.WARNING)
71-
72-
# # Suppress info logs from OpenTelemetry exporter
73-
logging.getLogger("azure.monitor.opentelemetry.exporter.export._base").setLevel(
74-
logging.WARNING
75-
)
76-
77-
logging.getLogger("opentelemetry.sdk").setLevel(
78-
logging.ERROR
79-
)
63+
# Configure logging levels from environment variables
64+
logging.basicConfig(level=getattr(logging, config.AZURE_BASIC_LOGGING_LEVEL.upper(), logging.INFO))
65+
66+
# Configure Azure package logging levels
67+
azure_level = getattr(logging, config.AZURE_PACKAGE_LOGGING_LEVEL.upper(), logging.WARNING)
68+
for logger_name in [
69+
"azure.core.pipeline.policies.http_logging_policy",
70+
"azure.identity.aio._internal",
71+
"azure.monitor.opentelemetry.exporter.export._base"
72+
]:
73+
logging.getLogger(logger_name).setLevel(azure_level)
74+
75+
logging.getLogger("opentelemetry.sdk").setLevel(logging.ERROR)
8076

8177
# Initialize the FastAPI app
8278
app = FastAPI(lifespan=lifespan)

src/backend/common/config/app_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ def __init__(self):
7373
# Azure Search settings
7474
self.AZURE_SEARCH_ENDPOINT = self._get_optional("AZURE_AI_SEARCH_ENDPOINT")
7575

76+
# Logging settings
77+
self.AZURE_BASIC_LOGGING_LEVEL = self._get_optional("AZURE_BASIC_LOGGING_LEVEL", "INFO")
78+
self.AZURE_PACKAGE_LOGGING_LEVEL = self._get_optional("AZURE_PACKAGE_LOGGING_LEVEL", "WARNING")
79+
7680
# Optional MCP server endpoint (for local MCP server or remote)
7781
# Example: http://127.0.0.1:8000/mcp
7882
self.MCP_SERVER_ENDPOINT = self._get_optional("MCP_SERVER_ENDPOINT")

0 commit comments

Comments
 (0)