Skip to content

Commit 0013dbe

Browse files
committed
fix: standardize OAuth logging levels for production readiness
- DEBUG: Normal operations (cache hits/stores, token validation, client lookups) - INFO: Important events (token refresh attempts/success, errors) - Reduces log noise in production while keeping essential information
1 parent 04928a9 commit 0013dbe

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/mxcp/sdk/auth/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ async def get_client(self, client_id: str) -> OAuthClientInformationFull | None:
257257
# First check memory cache
258258
client = self._clients.get(client_id)
259259
if client:
260-
logger.info(f"Looking up client_id: {client_id}, found in memory cache")
260+
logger.debug(f"Looking up client_id: {client_id}, found in memory cache")
261261
return client
262262

263263
# If not in cache and persistence is available, check persistence
@@ -300,7 +300,7 @@ async def get_client(self, client_id: str) -> OAuthClientInformationFull | None:
300300
client_name=persisted_client.client_name,
301301
)
302302
self._clients[client_id] = client
303-
logger.info(f"Looking up client_id: {client_id}, found in persistence")
303+
logger.debug(f"Looking up client_id: {client_id}, found in persistence")
304304
return client
305305
except Exception as e:
306306
logger.error(f"Error loading client from persistence: {e}")
@@ -557,7 +557,7 @@ async def load_authorization_code(
557557
code_challenge=persisted_code.code_challenge or "",
558558
)
559559
self._auth_codes[code] = auth_code
560-
logger.info(f"Loaded auth code from persistence: {code}")
560+
logger.debug(f"Loaded auth code from persistence: {code}")
561561
except Exception as e:
562562
logger.error(f"Error loading auth code from persistence: {e}")
563563

src/mxcp/sdk/auth/middleware.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ async def check_authentication(self) -> UserContext | None:
219219
)
220220
return None
221221

222-
logger.info("Access token found in request context")
222+
logger.debug("Access token found in request context")
223223
if span:
224224
span.set_attribute("mxcp.auth.has_token", True)
225225

@@ -245,7 +245,7 @@ async def check_authentication(self) -> UserContext | None:
245245
token_span.set_attribute("mxcp.auth.token_valid", True)
246246
token_span.set_attribute("mxcp.auth.client_id", token_info.client_id)
247247

248-
logger.info(f"Token validated successfully for client: {token_info.client_id}")
248+
logger.debug(f"Token validated successfully for client: {token_info.client_id}")
249249

250250
# Get the external token to fetch user context
251251
if not self.oauth_server:
@@ -257,7 +257,7 @@ async def check_authentication(self) -> UserContext | None:
257257
logger.warning("No external token mapping found")
258258
return None
259259

260-
logger.info("External token mapping found")
260+
logger.debug("External token mapping found")
261261

262262
# Get standardized user context from the provider (with caching)
263263
try:
@@ -274,7 +274,7 @@ async def check_authentication(self) -> UserContext | None:
274274
provider_name = getattr(
275275
self.oauth_handler, "__class__", type(self.oauth_handler)
276276
).__name__
277-
logger.info(
277+
logger.debug(
278278
f"🔄 Cache MISS - calling {provider_name}.get_user_context() - Provider API call #{hash(external_token) % 10000}"
279279
)
280280

@@ -320,7 +320,7 @@ async def check_authentication(self) -> UserContext | None:
320320
asyncio.create_task(self._cleanup_expired_cache_entries())
321321
# Add external token to the user context for use in DuckDB functions
322322
user_context.external_token = external_token
323-
logger.info(
323+
logger.debug(
324324
f"Successfully retrieved user context for {user_context.username} (provider: {user_context.provider})"
325325
)
326326

@@ -392,7 +392,7 @@ async def wrapper(*args: Any, **kwargs: Any) -> Any:
392392
user_context = await self.check_authentication()
393393
if user_context:
394394
# Log authentication status without PII
395-
logger.info(
395+
logger.debug(
396396
f"Executing {func.__name__} for authenticated user "
397397
f"(provider: {user_context.provider})"
398398
)

0 commit comments

Comments
 (0)