Spaces:
Sleeping
Sleeping
improve logging
Browse files
mcp/src/aileen3_mcp/cli_slides.py
CHANGED
|
@@ -10,10 +10,12 @@ import argparse
|
|
| 10 |
import sys
|
| 11 |
from pathlib import Path
|
| 12 |
|
|
|
|
| 13 |
from .media_tools import _build_reference, _extract_slides_flow, _probe_duration, _slides_json_path
|
| 14 |
|
| 15 |
|
| 16 |
def main(argv: list[str] | None = None) -> int:
|
|
|
|
| 17 |
parser = argparse.ArgumentParser(description="Extract slides from a video using the Gemini pipeline.")
|
| 18 |
parser.add_argument("video", type=Path, help="Path to the video file (mp4 recommended).")
|
| 19 |
parser.add_argument(
|
|
|
|
| 10 |
import sys
|
| 11 |
from pathlib import Path
|
| 12 |
|
| 13 |
+
from .logging_utils import configure_logging
|
| 14 |
from .media_tools import _build_reference, _extract_slides_flow, _probe_duration, _slides_json_path
|
| 15 |
|
| 16 |
|
| 17 |
def main(argv: list[str] | None = None) -> int:
|
| 18 |
+
configure_logging()
|
| 19 |
parser = argparse.ArgumentParser(description="Extract slides from a video using the Gemini pipeline.")
|
| 20 |
parser.add_argument("video", type=Path, help="Path to the video file (mp4 recommended).")
|
| 21 |
parser.add_argument(
|
mcp/src/aileen3_mcp/logging_utils.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
# Logging paths
|
| 8 |
+
BASE_CACHE = Path(os.environ.get("AILEEN3_CACHE_DIR", Path.home() / ".cache" / "aileen3"))
|
| 9 |
+
LOG_DIR = BASE_CACHE / "logs"
|
| 10 |
+
LOG_FILE = LOG_DIR / "aileen3-mcp.log"
|
| 11 |
+
PACKAGE_LOGGER_NAME = "aileen3_mcp"
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def _resolve_level() -> int:
|
| 15 |
+
level_name = os.environ.get("AILEEN3_LOGLEVEL", "").upper() or "INFO"
|
| 16 |
+
level = getattr(logging, level_name, None)
|
| 17 |
+
if isinstance(level, int):
|
| 18 |
+
return level
|
| 19 |
+
# Fallback for non-standard levels
|
| 20 |
+
try:
|
| 21 |
+
return int(level_name)
|
| 22 |
+
except Exception:
|
| 23 |
+
return logging.INFO
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def configure_logging() -> Path:
|
| 27 |
+
"""Configure package logging without turning on DEBUG for third-party libs."""
|
| 28 |
+
LOG_DIR.mkdir(parents=True, exist_ok=True)
|
| 29 |
+
level = _resolve_level()
|
| 30 |
+
|
| 31 |
+
pkg_logger = logging.getLogger(PACKAGE_LOGGER_NAME)
|
| 32 |
+
pkg_logger.setLevel(level)
|
| 33 |
+
pkg_logger.propagate = False # keep third-party noise out of our handler
|
| 34 |
+
|
| 35 |
+
existing = None
|
| 36 |
+
for h in pkg_logger.handlers:
|
| 37 |
+
if isinstance(h, logging.FileHandler) and Path(getattr(h, "baseFilename", "")) == LOG_FILE:
|
| 38 |
+
existing = h
|
| 39 |
+
break
|
| 40 |
+
|
| 41 |
+
if existing:
|
| 42 |
+
existing.setLevel(level)
|
| 43 |
+
else:
|
| 44 |
+
handler = logging.FileHandler(LOG_FILE, encoding="utf-8")
|
| 45 |
+
handler.setLevel(level)
|
| 46 |
+
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(name)s: %(message)s"))
|
| 47 |
+
pkg_logger.addHandler(handler)
|
| 48 |
+
|
| 49 |
+
return LOG_FILE
|
mcp/src/aileen3_mcp/media_tools.py
CHANGED
|
@@ -39,27 +39,6 @@ DEBUG_DIR = Path(tempfile.gettempdir()) / "aileen3-debug"
|
|
| 39 |
if DEBUG:
|
| 40 |
DEBUG_DIR.mkdir(parents=True, exist_ok=True)
|
| 41 |
|
| 42 |
-
LOG_DIR = BASE_CACHE / "logs"
|
| 43 |
-
LOG_DIR.mkdir(parents=True, exist_ok=True)
|
| 44 |
-
LOG_FILE = LOG_DIR / "aileen3-mcp.log"
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
def _ensure_file_logging():
|
| 48 |
-
root = logging.getLogger()
|
| 49 |
-
# Avoid adding duplicate handlers to root
|
| 50 |
-
for h in root.handlers:
|
| 51 |
-
if isinstance(h, logging.FileHandler) and Path(getattr(h, "baseFilename", "")) == LOG_FILE:
|
| 52 |
-
return
|
| 53 |
-
handler = logging.FileHandler(LOG_FILE, encoding="utf-8")
|
| 54 |
-
handler.setLevel(logging.DEBUG if DEBUG else logging.INFO)
|
| 55 |
-
fmt = logging.Formatter("%(asctime)s [%(levelname)s] %(name)s: %(message)s")
|
| 56 |
-
handler.setFormatter(fmt)
|
| 57 |
-
root.addHandler(handler)
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
_ensure_file_logging()
|
| 61 |
-
|
| 62 |
-
|
| 63 |
def _write_debug(reference: str, suffix: str, data: Any) -> None:
|
| 64 |
if not DEBUG:
|
| 65 |
return
|
|
|
|
| 39 |
if DEBUG:
|
| 40 |
DEBUG_DIR.mkdir(parents=True, exist_ok=True)
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
def _write_debug(reference: str, suffix: str, data: Any) -> None:
|
| 43 |
if not DEBUG:
|
| 44 |
return
|
mcp/src/aileen3_mcp/server.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
-
import logging
|
| 4 |
import os
|
| 5 |
from dataclasses import asdict, dataclass
|
| 6 |
|
|
@@ -10,6 +9,9 @@ import subprocess
|
|
| 10 |
from fastmcp import FastMCP
|
| 11 |
|
| 12 |
from aileen3_mcp.media_tools import register_media_tools, _silence_stdio, _YDLLogger
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
log = logging.getLogger(__name__)
|
| 15 |
|
|
@@ -138,7 +140,7 @@ def make_app() -> FastMCP:
|
|
| 138 |
|
| 139 |
|
| 140 |
def main() -> None:
|
| 141 |
-
|
| 142 |
app = make_app()
|
| 143 |
app.run() # stdio transport by default
|
| 144 |
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
|
|
|
| 3 |
import os
|
| 4 |
from dataclasses import asdict, dataclass
|
| 5 |
|
|
|
|
| 9 |
from fastmcp import FastMCP
|
| 10 |
|
| 11 |
from aileen3_mcp.media_tools import register_media_tools, _silence_stdio, _YDLLogger
|
| 12 |
+
from aileen3_mcp.logging_utils import configure_logging
|
| 13 |
+
|
| 14 |
+
import logging
|
| 15 |
|
| 16 |
log = logging.getLogger(__name__)
|
| 17 |
|
|
|
|
| 140 |
|
| 141 |
|
| 142 |
def main() -> None:
|
| 143 |
+
configure_logging()
|
| 144 |
app = make_app()
|
| 145 |
app.run() # stdio transport by default
|
| 146 |
|