2121# Semantic Kernel imports
2222from v3 .config .agent_registry import agent_registry
2323
24- # Configure logging levels from environment variables (force configuration)
25- basic_level = getattr (logging , config .AZURE_BASIC_LOGGING_LEVEL .upper (), logging .INFO )
26- logging .getLogger ().setLevel (basic_level ) # Force root logger level
27- logging .basicConfig (level = basic_level , force = True ) # Force reconfiguration
28-
29- # Configure Azure package logging levels
30- azure_level = getattr (logging , config .AZURE_PACKAGE_LOGGING_LEVEL .upper (), logging .WARNING )
31- # Parse comma-separated logging packages
32- packages = []
33- if config .AZURE_LOGGING_PACKAGES :
34- packages = [pkg .strip () for pkg in config .AZURE_LOGGING_PACKAGES .split ("," ) if pkg .strip ()]
35- for logger_name in packages :
36- logging .getLogger (logger_name ).setLevel (azure_level )
37-
38- logging .info (f"Logging configured - Basic: { basic_level } , Azure packages: { azure_level } , Packages: { packages } " )
39-
4024
4125@asynccontextmanager
4226async def lifespan (app : FastAPI ):
@@ -75,6 +59,20 @@ async def lifespan(app: FastAPI):
7559 logging .warning (
7660 "No Application Insights Instrumentation Key found. Skipping configuration"
7761 )
62+
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+ # Parse comma-separated logging packages
69+ if config .AZURE_LOGGING_PACKAGES :
70+ packages = [pkg .strip () for pkg in config .AZURE_LOGGING_PACKAGES .split ("," ) if pkg .strip ()]
71+ for logger_name in packages :
72+ logging .getLogger (logger_name ).setLevel (azure_level )
73+
74+ logging .getLogger ("opentelemetry.sdk" ).setLevel (logging .ERROR )
75+
7876# Initialize the FastAPI app
7977app = FastAPI (lifespan = lifespan )
8078
@@ -139,4 +137,4 @@ async def user_browser_language_endpoint(user_language: UserLanguage, request: R
139137 reload = True ,
140138 log_level = "info" ,
141139 access_log = False ,
142- )
140+ )
0 commit comments