29 lines
867 B
Python
29 lines
867 B
Python
#!/usr/bin/env python3
|
|
"""Logging to both stderr and the shared log file.
|
|
|
|
Kept trivial and dependency-free on purpose: systemd captures stderr, while the
|
|
file gives the same `[timestamp] message` shape the legacy shell pipeline wrote,
|
|
so existing habits (`tail -f OBSIDIAN/logs/…`) keep working.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import threading
|
|
import time
|
|
|
|
from .config import CFG
|
|
|
|
_lk = threading.Lock()
|
|
|
|
|
|
def log(msg: str, *, level: str = "INFO") -> None:
|
|
line = f"[{time.strftime('%F %T %z')}] {level}: {msg}"
|
|
with _lk:
|
|
print(line, file=sys.stderr, flush=True)
|
|
try:
|
|
CFG.log_file.parent.mkdir(parents=True, exist_ok=True)
|
|
with CFG.log_file.open("a", encoding="utf-8") as f:
|
|
f.write(line + "\n")
|
|
except Exception:
|
|
pass # never let logging break the pipeline
|