fix(gateway): timestamp shared stderr output

This commit is contained in:
doncazper
2026-07-15 13:32:41 -07:00
committed by Teknium
parent 1db9273584
commit 6a375a24a5
4 changed files with 49 additions and 6 deletions
+9 -1
View File
@@ -3,6 +3,7 @@
from __future__ import annotations
import argparse
import re
import signal
import subprocess
import sys
@@ -11,13 +12,20 @@ from pathlib import Path
from typing import BinaryIO, Sequence, TextIO
_TIMESTAMP_PREFIX = re.compile(
r"^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}(?:\s|$)"
)
def _timestamp() -> str:
"""Match logging.Formatter's default ``%(asctime)s`` timestamp shape."""
return datetime.now().strftime("%Y-%m-%d %H:%M:%S,%f")[:23]
def _write_timestamped_line(log_file: TextIO, line: str) -> None:
log_file.write(f"{_timestamp()} {line.rstrip(chr(10))}\n")
rendered = line.rstrip("\r\n")
prefix = "" if _TIMESTAMP_PREFIX.match(rendered) else f"{_timestamp()} "
log_file.write(f"{prefix}{rendered}\n")
log_file.flush()