mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-08-12 12:13:21 +00:00
remove intermediate documentation comments and unused search module
This commit is contained in:
@@ -370,8 +370,6 @@ async def pay_for_request(
|
||||
|
||||
await session.refresh(key)
|
||||
|
||||
# IMPORTANT: Do not modify this log message - used for usage statistics tracking
|
||||
# This log is parsed to count successful payment processing events
|
||||
logger.info(
|
||||
"Payment processed successfully",
|
||||
extra={
|
||||
@@ -401,8 +399,6 @@ async def revert_pay_for_request(
|
||||
result = await session.exec(stmt) # type: ignore[call-overload]
|
||||
await session.commit()
|
||||
if result.rowcount == 0:
|
||||
# IMPORTANT: Do not modify this log message - used for usage statistics tracking
|
||||
# This error log indicates a refund failure (tracked separately from successful refunds)
|
||||
logger.error(
|
||||
"Failed to revert payment - insufficient reserved balance",
|
||||
extra={
|
||||
|
||||
@@ -141,8 +141,6 @@ async def proxy(
|
||||
"unauthorized", "Unauthorized", 401, request=request
|
||||
)
|
||||
|
||||
# IMPORTANT: Do not modify this log message - used for usage statistics tracking
|
||||
# This log is parsed by the usage tracking system to count total requests
|
||||
logger.info( # TODO: move to middleware, async
|
||||
"Received proxy request",
|
||||
extra={
|
||||
@@ -224,9 +222,6 @@ async def proxy(
|
||||
|
||||
if response.status_code != 200:
|
||||
await revert_pay_for_request(key, session, max_cost_for_model)
|
||||
# IMPORTANT: Do not modify this log message - used for usage statistics tracking
|
||||
# This log is parsed to track refunds and failed requests
|
||||
# The 'max_cost_for_model' field is used to calculate total refunds
|
||||
logger.warning(
|
||||
"Upstream request failed, revert payment",
|
||||
extra={
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
from .log_search import search_logs
|
||||
|
||||
__all__ = ["search_logs"]
|
||||
@@ -1,108 +0,0 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
|
||||
def search_logs(
|
||||
logs_dir: Path,
|
||||
date: str | None = None,
|
||||
level: str | None = None,
|
||||
request_id: str | None = None,
|
||||
search_text: str | None = None,
|
||||
limit: int = 100,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""
|
||||
Search through log files and return matching entries.
|
||||
Args:
|
||||
logs_dir: Path to the logs directory
|
||||
date: Filter by specific date (YYYY-MM-DD format)
|
||||
level: Filter by log level (INFO, WARNING, ERROR, etc.)
|
||||
request_id: Filter by exact request ID match
|
||||
search_text: Search in message and name fields (case-insensitive)
|
||||
limit: Maximum number of entries to return
|
||||
|
||||
Returns:
|
||||
List of log entries matching the criteria
|
||||
"""
|
||||
log_entries: list[dict[str, Any]] = []
|
||||
|
||||
if not logs_dir.exists():
|
||||
return log_entries
|
||||
|
||||
log_files = []
|
||||
if date:
|
||||
log_file = logs_dir / f"app_{date}.log"
|
||||
if log_file.exists():
|
||||
log_files.append(log_file)
|
||||
else:
|
||||
log_files = sorted(
|
||||
logs_dir.glob("app_*.log"),
|
||||
key=lambda x: x.stat().st_mtime,
|
||||
reverse=True,
|
||||
)[:7]
|
||||
|
||||
search_text_lower = search_text.lower() if search_text else None
|
||||
|
||||
for log_file in log_files:
|
||||
try:
|
||||
with open(log_file, "r") as f:
|
||||
for line in f:
|
||||
try:
|
||||
log_data = json.loads(line.strip())
|
||||
|
||||
if not _matches_filters(
|
||||
log_data, level, request_id, search_text_lower
|
||||
):
|
||||
continue
|
||||
|
||||
log_entries.append(log_data)
|
||||
|
||||
if len(log_entries) >= limit:
|
||||
break
|
||||
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
|
||||
if len(log_entries) >= limit:
|
||||
break
|
||||
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
log_entries.sort(key=lambda x: x.get("asctime", ""), reverse=True)
|
||||
|
||||
return log_entries
|
||||
|
||||
|
||||
def _matches_filters(
|
||||
log_data: dict[str, Any],
|
||||
level: str | None,
|
||||
request_id: str | None,
|
||||
search_text_lower: str | None,
|
||||
) -> bool:
|
||||
"""
|
||||
Check if a log entry matches the given filters.
|
||||
|
||||
Args:
|
||||
log_data: The log entry to check
|
||||
level: Log level filter (if any)
|
||||
request_id: Request ID filter (if any)
|
||||
search_text_lower: Lowercase search text (if any)
|
||||
|
||||
Returns:
|
||||
True if the log entry matches all filters, False otherwise
|
||||
"""
|
||||
if level and log_data.get("levelname", "").upper() != level.upper():
|
||||
return False
|
||||
|
||||
if request_id and log_data.get("request_id") != request_id:
|
||||
return False
|
||||
|
||||
if search_text_lower:
|
||||
message = str(log_data.get("message", "")).lower()
|
||||
name = str(log_data.get("name", "")).lower()
|
||||
|
||||
if search_text_lower not in message and search_text_lower not in name:
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -452,9 +452,6 @@ class BaseUpstreamProvider:
|
||||
)
|
||||
)
|
||||
usage_finalized = True
|
||||
# IMPORTANT: Do not modify this log message - used for usage statistics tracking
|
||||
# This log is parsed to track revenue from successful requests
|
||||
# The 'cost_data.total_msats' field is used to calculate total revenue
|
||||
logger.info(
|
||||
"Payment adjustment completed for streaming",
|
||||
extra={
|
||||
@@ -559,9 +556,6 @@ class BaseUpstreamProvider:
|
||||
)
|
||||
response_json["cost"] = cost_data
|
||||
|
||||
# IMPORTANT: Do not modify this log message - used for usage statistics tracking
|
||||
# This log is parsed to track revenue from successful requests
|
||||
# The 'cost_data.total_msats' field is used to calculate total revenue
|
||||
logger.info(
|
||||
"Payment adjustment completed for non-streaming",
|
||||
extra={
|
||||
|
||||
Reference in New Issue
Block a user