From 41856690519fed26bb9e35095fd8e72d54316497 Mon Sep 17 00:00:00 2001 From: tangwang Date: Fri, 20 Mar 2026 21:08:52 +0800 Subject: [PATCH] embedding logs --- embeddings/server.py | 48 ++++++++---------------------------------------- frontend/static/css/style.css | 15 +++++---------- frontend/static/js/app.js | 84 ++++++++++++++++++++++++++++-------------------------------------------------------- scripts/start_embedding_service.sh | 10 +++++++++- 4 files changed, 50 insertions(+), 107 deletions(-) diff --git a/embeddings/server.py b/embeddings/server.py index 8e80321..c03c939 100644 --- a/embeddings/server.py +++ b/embeddings/server.py @@ -14,7 +14,6 @@ import time import uuid from collections import deque from dataclasses import dataclass -from logging.handlers import TimedRotatingFileHandler from typing import Any, Dict, List, Optional import numpy as np @@ -44,9 +43,7 @@ def configure_embedding_logging() -> None: return log_dir = pathlib.Path("logs") - verbose_dir = log_dir / "verbose" log_dir.mkdir(exist_ok=True) - verbose_dir.mkdir(parents=True, exist_ok=True) log_level = os.getenv("LOG_LEVEL", "INFO").upper() numeric_level = getattr(logging, log_level, logging.INFO) @@ -56,47 +53,18 @@ def configure_embedding_logging() -> None: request_filter = _DefaultRequestIdFilter() root_logger.setLevel(numeric_level) - - file_handler = TimedRotatingFileHandler( - filename=log_dir / "embedding_api.log", - when="midnight", - interval=1, - backupCount=30, - encoding="utf-8", - ) - file_handler.setLevel(numeric_level) - file_handler.setFormatter(formatter) - file_handler.addFilter(request_filter) - root_logger.addHandler(file_handler) - - error_handler = TimedRotatingFileHandler( - filename=log_dir / "embedding_api_error.log", - when="midnight", - interval=1, - backupCount=30, - encoding="utf-8", - ) - error_handler.setLevel(logging.ERROR) - error_handler.setFormatter(formatter) - error_handler.addFilter(request_filter) - root_logger.addHandler(error_handler) + root_logger.handlers.clear() + stream_handler = logging.StreamHandler() + stream_handler.setLevel(numeric_level) + stream_handler.setFormatter(formatter) + stream_handler.addFilter(request_filter) + root_logger.addHandler(stream_handler) verbose_logger = logging.getLogger("embedding.verbose") verbose_logger.setLevel(numeric_level) verbose_logger.handlers.clear() - verbose_logger.propagate = False - - verbose_handler = TimedRotatingFileHandler( - filename=verbose_dir / "embedding_verbose.log", - when="midnight", - interval=1, - backupCount=30, - encoding="utf-8", - ) - verbose_handler.setLevel(numeric_level) - verbose_handler.setFormatter(formatter) - verbose_handler.addFilter(request_filter) - verbose_logger.addHandler(verbose_handler) + # Consolidate verbose logs into the main embedding log stream. + verbose_logger.propagate = True root_logger._embedding_logging_configured = True # type: ignore[attr-defined] diff --git a/frontend/static/css/style.css b/frontend/static/css/style.css index 0eda895..ac81869 100644 --- a/frontend/static/css/style.css +++ b/frontend/static/css/style.css @@ -379,7 +379,7 @@ body { margin-top: 8px; } -.product-debug-inline-es-btn { +.product-debug-inline-result-btn { font-family: inherit; font-size: 12px; padding: 4px 10px; @@ -390,27 +390,22 @@ body { cursor: pointer; } -.product-debug-inline-es-btn:hover { +.product-debug-inline-result-btn:hover { background: #f0f0f0; border-color: #bbb; } -.product-debug--es-expanded { +.product-debug--result-expanded { max-height: min(70vh, 720px); } -.product-es-doc-panel { +.product-result-doc-panel { margin-top: 10px; padding-top: 8px; border-top: 1px dashed #e8e8e8; } -.product-es-doc-panel-status { - font-size: 12px; - color: #888; -} - -.product-es-doc-pre { +.product-result-doc-pre { margin: 6px 0 0; padding: 10px; background: #f5f5f5; diff --git a/frontend/static/js/app.js b/frontend/static/js/app.js index 34ad312..82b9857 100644 --- a/frontend/static/js/app.js +++ b/frontend/static/js/app.js @@ -68,25 +68,25 @@ function initializeApp() { // 初始化租户下拉框和分面面板 console.log('Initializing app...'); initTenantSelect(); - setupProductGridEsDocToggle(); + setupProductGridResultDocToggle(); const searchInput = document.getElementById('searchInput'); if (searchInput) { searchInput.focus(); } } -/** Delegated handler: toggle inline ES raw response under each result card (survives innerHTML refresh on re-search). */ -function setupProductGridEsDocToggle() { +/** Delegated handler: toggle inline current result JSON under each result card (survives innerHTML refresh on re-search). */ +function setupProductGridResultDocToggle() { const grid = document.getElementById('productGrid'); - if (!grid || grid.dataset.esDocToggleBound === '1') { + if (!grid || grid.dataset.resultDocToggleBound === '1') { return; } - grid.dataset.esDocToggleBound = '1'; - grid.addEventListener('click', onProductGridEsDocToggleClick); + grid.dataset.resultDocToggleBound = '1'; + grid.addEventListener('click', onProductGridResultDocToggleClick); } -async function onProductGridEsDocToggleClick(event) { - const btn = event.target.closest('[data-action="toggle-es-inline-doc"]'); +function onProductGridResultDocToggleClick(event) { + const btn = event.target.closest('[data-action="toggle-result-inline-doc"]'); if (!btn) { return; } @@ -95,55 +95,27 @@ async function onProductGridEsDocToggleClick(event) { if (!debugRoot) { return; } - const panel = debugRoot.querySelector('.product-es-doc-panel'); - const pre = debugRoot.querySelector('.product-es-doc-pre'); - const statusEl = debugRoot.querySelector('.product-es-doc-panel-status'); - if (!panel || !pre || !statusEl) { + const panel = debugRoot.querySelector('.product-result-doc-panel'); + const pre = debugRoot.querySelector('.product-result-doc-pre'); + if (!panel || !pre) { return; } - const spuId = btn.getAttribute('data-spu-id') || ''; - const tenantId = getTenantId(); - const url = `${API_BASE_URL}/search/es-doc/${encodeURIComponent(spuId)}?tenant_id=${encodeURIComponent(tenantId)}`; - - if (debugRoot.dataset.esInlineOpen === '1') { + if (debugRoot.dataset.resultInlineOpen === '1') { panel.setAttribute('hidden', ''); - debugRoot.classList.remove('product-debug--es-expanded'); - debugRoot.dataset.esInlineOpen = '0'; - btn.textContent = '在结果中显示 ES 文档'; + debugRoot.classList.remove('product-debug--result-expanded'); + debugRoot.dataset.resultInlineOpen = '0'; + btn.textContent = '在结果中显示当前结果数据'; return; } panel.removeAttribute('hidden'); - debugRoot.classList.add('product-debug--es-expanded'); - debugRoot.dataset.esInlineOpen = '1'; - btn.textContent = '隐藏 ES 文档'; - - if (pre.textContent.length > 0) { - panel.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); - return; - } - - statusEl.style.display = ''; - statusEl.textContent = '加载中…'; - pre.style.display = 'none'; - - try { - const response = await fetch(url); - if (!response.ok) { - const errText = await response.text(); - throw new Error(`HTTP ${response.status}: ${errText.slice(0, 200)}`); - } - const data = await response.json(); - pre.textContent = customStringify(data); - statusEl.style.display = 'none'; - pre.style.display = 'block'; - } catch (err) { - console.error('ES doc fetch failed', err); - statusEl.textContent = `加载失败: ${err.message || err}`; - pre.style.display = 'none'; + debugRoot.classList.add('product-debug--result-expanded'); + debugRoot.dataset.resultInlineOpen = '1'; + btn.textContent = '隐藏当前结果数据'; + if (pre.textContent.length === 0) { + pre.textContent = btn.getAttribute('data-result-json') || '{}'; } - panel.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); } @@ -213,7 +185,7 @@ function initTenantSelect() { }); // 设置默认值(仅当输入框为空时) if (!tenantSelect.value.trim()) { - tenantSelect.value = availableTenants.includes('170') ? '170' : availableTenants[0]; + tenantSelect.value = availableTenants.includes('0') ? '0' : availableTenants[0]; } } @@ -462,6 +434,7 @@ function displayResults(data) { }); } + const resultJson = customStringify(result); const rawUrl = `${API_BASE_URL}/search/es-doc/${encodeURIComponent(spuId)}?tenant_id=${encodeURIComponent(tenantId)}`; debugHtml = ` @@ -475,18 +448,17 @@ function displayResults(data) {
Fused score: ${fusedScore}
${titleLines}
- 查看 ES 原始文档
- `; diff --git a/scripts/start_embedding_service.sh b/scripts/start_embedding_service.sh index c6fe560..c761a1f 100755 --- a/scripts/start_embedding_service.sh +++ b/scripts/start_embedding_service.sh @@ -138,7 +138,11 @@ fi if [[ "${IMAGE_MODEL_ENABLED}" == "1" ]]; then echo "Image max inflight: ${IMAGE_MAX_INFLIGHT:-1}" fi -echo "Logs: logs/embedding_api.log, logs/embedding_api_error.log, logs/verbose/embedding_verbose.log" +if [[ "${SERVICE_KIND}" == "image" ]]; then + echo "Logs: logs/embedding-image.log" +else + echo "Logs: logs/embedding.log" +fi echo echo "Tips:" echo " - Use a single worker (GPU models cannot be safely duplicated across workers)." @@ -153,12 +157,16 @@ echo UVICORN_LOG_LEVEL="${EMBEDDING_UVICORN_LOG_LEVEL:-info}" UVICORN_ACCESS_LOG="${EMBEDDING_UVICORN_ACCESS_LOG:-true}" +UVICORN_LOG_CONFIG="${EMBEDDING_UVICORN_LOG_CONFIG:-${PROJECT_ROOT}/config/uvicorn_embedding_logging.json}" UVICORN_ARGS=( --host "${EMBEDDING_SERVICE_HOST}" --port "${EMBEDDING_SERVICE_PORT}" --workers 1 --log-level "${UVICORN_LOG_LEVEL}" ) +if [[ -f "${UVICORN_LOG_CONFIG}" ]]; then + UVICORN_ARGS+=(--log-config "${UVICORN_LOG_CONFIG}") +fi if [[ "${UVICORN_ACCESS_LOG}" == "0" || "${UVICORN_ACCESS_LOG}" == "false" || "${UVICORN_ACCESS_LOG}" == "no" ]]; then UVICORN_ARGS+=(--no-access-log) fi -- libgit2 0.21.2