fix: use lazy %s formatting in all logger calls for consistent deferred evaluation

This commit is contained in:
Zamil Majdy
2026-03-17 04:06:46 +07:00
parent a08673cdbe
commit 40f5532b1e
2 changed files with 29 additions and 19 deletions

View File

@@ -179,7 +179,7 @@ def _get_enabled_blocks() -> dict[str, AnyBlockSchema]:
try:
instance = block_cls()
except Exception as e:
logger.warning(f"Skipping block {block_id}: init failed: {e}")
logger.warning("Skipping block %s: init failed: %s", block_id, e)
continue
if not instance.disabled:
enabled[block_id] = instance
@@ -227,7 +227,8 @@ class BlockHandler(ContentHandler):
# Build searchable text from block metadata
if not block.name:
logger.warning(
f"Block {block_id} has no name — using block_id as fallback"
"Block %s has no name — using block_id as fallback",
block_id,
)
display_name = split_camelcase(block.name) if block.name else ""
parts = []
@@ -282,7 +283,7 @@ class BlockHandler(ContentHandler):
)
)
except Exception as e:
logger.warning(f"Failed to process block {block_id}: {e}")
logger.warning("Failed to process block %s: %s", block_id, e)
continue
return items
@@ -367,7 +368,7 @@ class DocumentationHandler(ContentHandler):
# If no title found, use filename
return file_path.stem.replace("-", " ").replace("_", " ").title()
except Exception as e:
logger.warning(f"Failed to read title from {file_path}: {e}")
logger.warning("Failed to read title from %s: %s", file_path, e)
return file_path.stem.replace("-", " ").replace("_", " ").title()
def _chunk_markdown_by_headings(
@@ -387,7 +388,7 @@ class DocumentationHandler(ContentHandler):
try:
content = file_path.read_text(encoding="utf-8")
except Exception as e:
logger.warning(f"Failed to read {file_path}: {e}")
logger.warning("Failed to read %s: %s", file_path, e)
return []
lines = content.split("\n")
@@ -512,7 +513,7 @@ class DocumentationHandler(ContentHandler):
docs_root = self._get_docs_root()
if not docs_root.exists():
logger.warning(f"Documentation root not found: {docs_root}")
logger.warning("Documentation root not found: %s", docs_root)
return []
# Find all .md and .mdx files
@@ -588,7 +589,7 @@ class DocumentationHandler(ContentHandler):
)
)
except Exception as e:
logger.warning(f"Failed to process section {content_id}: {e}")
logger.warning("Failed to process section %s: %s", content_id, e)
continue
return items

View File

@@ -190,8 +190,9 @@ async def unified_hybrid_search(
query_embedding = await embed_query(query)
except Exception as e:
logger.warning(
f"Failed to generate query embedding - falling back to lexical-only search: {e}. "
"Check that openai_internal_api_key is configured and OpenAI API is accessible."
"Failed to generate query embedding - falling back to lexical-only search: %s. "
"Check that openai_internal_api_key is configured and OpenAI API is accessible.",
e,
)
query_embedding = [0.0] * EMBEDDING_DIM
# Redistribute semantic weight to lexical
@@ -382,7 +383,7 @@ async def unified_hybrid_search(
for result in results:
result.pop("total_count", None)
logger.info(f"Unified hybrid search: {len(results)} results, {total} total")
logger.info("Unified hybrid search: %d results, %d total", len(results), total)
return results, total
@@ -471,7 +472,8 @@ async def hybrid_search(
query_embedding = await embed_query(query)
except Exception as e:
logger.warning(
f"Failed to generate query embedding - falling back to lexical-only search: {e}"
"Failed to generate query embedding - falling back to lexical-only search: %s",
e,
)
query_embedding = [0.0] * EMBEDDING_DIM
total_non_semantic = (
@@ -711,7 +713,9 @@ async def hybrid_search(
result.pop("total_count", None)
result.pop("searchable_text", None)
logger.info(f"Hybrid search (store agents): {len(results)} results, {total} total")
logger.info(
"Hybrid search (store agents): %d results, %d total", len(results), total
)
return results, total
@@ -795,15 +799,20 @@ async def _log_vector_error_diagnostics(error: Exception) -> None:
diagnostics["pgvector_extension"] = f"Error: {e}"
logger.error(
f"Vector type error diagnostics:\n"
f" Error: {error}\n"
f" search_path: {diagnostics.get('search_path')}\n"
f" current_schema: {diagnostics.get('current_schema')}\n"
f" user_info: {diagnostics.get('user_info')}\n"
f" pgvector_extension: {diagnostics.get('pgvector_extension')}"
"Vector type error diagnostics:\n"
" Error: %s\n"
" search_path: %s\n"
" current_schema: %s\n"
" user_info: %s\n"
" pgvector_extension: %s",
error,
diagnostics.get("search_path"),
diagnostics.get("current_schema"),
diagnostics.get("user_info"),
diagnostics.get("pgvector_extension"),
)
except Exception as diag_error:
logger.error(f"Failed to collect vector error diagnostics: {diag_error}")
logger.error("Failed to collect vector error diagnostics: %s", diag_error)
# Backward compatibility alias - HybridSearchWeights maps to StoreAgentSearchWeights