Files
hao-ai-lab-FastVideo/apps/dreamverse/server/session_logger.py
T
SolitaryThinker aef113a861 [fix] dreamverse-monorepo: carry generic-merged files product-local
Source: Dreamverse repo at will/integrate-public-fastvideo @ ec8ef92.\n\nCarry the generic-merged backend modules as Dreamverse product-local code because the public streaming APIs are not drop-in compatible with the product runtime yet. Revert the Phase 2 public compatibility shims so FastVideo's public streaming surface returns to the pre-migration state.\n\nCo-authored-by: Junda (David) Su <90978028+Davids048@users.noreply.github.com>\nCo-authored-by: Matthew Noto <99706358+RandNMR73@users.noreply.github.com>\nCo-authored-by: XOR-op <17672363+XOR-op@users.noreply.github.com>\nCo-authored-by: Zhang Peiyuan <42993249+jzhang38@users.noreply.github.com>
2026-05-07 13:37:25 -07:00

47 lines
1.2 KiB
Python

# pyright: reportMissingTypeArgument=false
from __future__ import annotations
import asyncio
from datetime import datetime, timezone
import json
import socket
from pathlib import Path
from typing import Any
def _utc_now_iso() -> str:
return datetime.now(timezone.utc).isoformat()
class SessionEventLogger:
def __init__(self, root_dir: Path):
self.hostname = socket.gethostname()
timestamp = datetime.now(timezone.utc).strftime("%y%m%d_%H%M%S")
self.directory = root_dir / self.hostname
self.path = self.directory / f"{timestamp}.jsonl"
self._lock = asyncio.Lock()
self.directory.mkdir(parents=True, exist_ok=True)
self.path.touch(exist_ok=False)
async def write_event(
self,
*,
event: str,
client_id: str,
payload: dict[str, Any] | None = None,
) -> None:
entry = {
"ts": _utc_now_iso(),
"event": event,
"hostname": self.hostname,
"client_id": client_id,
}
if payload:
entry.update(payload)
async with self._lock:
with self.path.open("a", encoding="utf-8") as fp:
fp.write(json.dumps(entry, ensure_ascii=False) + "\n")