Files
lintunes/lintunes/eventlog.py
T
trav e7f23dec36 v0.1.4: playback-control provenance log
LinTunes has spontaneously resumed playback for ~4s (then paused) four
times while trav was away — suspected phantom media-key events from the
Audioengine USB DAC's HID 'keyboard', but the pathway (MPRIS vs the
focused-window key filter) is unproven. Every control path now drops a
timestamped line in ~/.cache/lintunes/control-events.log: MPRIS Player
methods, the media-key eventFilter (with source input device where the
compositor exposes it), and Player.toggle_play/pause with position. New
lintunes/eventlog.py, 1MB rotation, never raises; conftest autouse
fixture keeps tests off the real log file.
2026-07-10 18:09:21 -04:00

38 lines
1.3 KiB
Python

"""Append-only provenance log for playback-control events.
Every path that can start/stop playback (MPRIS calls, the media-key
eventFilter, the Player's transport methods) drops a one-line record here,
so "the app played by itself" incidents can be attributed after the fact:
which pathway fired, when, and — for D-Bus — who sent it. Written to
~/.cache/lintunes/control-events.log (survives app restarts and doesn't
depend on how the app was launched); mirrored to the standard logger.
"""
import logging
import time
from pathlib import Path
log = logging.getLogger("lintunes.control")
_MAX_BYTES = 1_000_000
def _log_path() -> Path:
return Path.home() / ".cache" / "lintunes" / "control-events.log"
def log_control(source: str, action: str, detail: str = ""):
"""Record a playback-control event; never raises."""
line = f"{time.strftime('%F %T')} [{source}] {action}"
if detail:
line += f" {detail}"
log.info("[%s] %s %s", source, action, detail)
try:
path = _log_path()
path.parent.mkdir(parents=True, exist_ok=True)
if path.exists() and path.stat().st_size > _MAX_BYTES:
path.replace(path.with_suffix(".log.old"))
with open(path, "a", encoding="utf-8") as f:
f.write(line + "\n")
except Exception:
pass # a provenance logger must never break playback