diff --git a/modjam/log.py b/modjam/log.py index a200ca9..1bddce6 100644 --- a/modjam/log.py +++ b/modjam/log.py @@ -11,9 +11,10 @@ class TsvLogger: received: received """ - def __init__(self, station: str, log_dir: str | Path = "."): + def __init__(self, station: str, log_dir: str | Path = ".", test_name: str | None = None): Path(log_dir).mkdir(parents=True, exist_ok=True) - path = Path(log_dir) / f"{station}-{int(time())}.tsv" + prefix = f"{test_name}-{station}" if test_name else station + path = Path(log_dir) / f"{prefix}-{int(time())}.tsv" self._fh: IO = open(path, "a", buffering=1) # line-buffered self.path = path diff --git a/modjam/station.py b/modjam/station.py index 1c9f468..15b3677 100644 --- a/modjam/station.py +++ b/modjam/station.py @@ -117,7 +117,11 @@ class TestStation: cues = cuesheet.build(cue_params) print(f"[run] {len(cues)} cases, ~{(cues[-1].done_at - base_t) / 3600:.2f}h, base_t={base_t}") - self._logger = TsvLogger(self.cfg.this_station_name, self.cfg.log_dir) + self._logger = TsvLogger( + self.cfg.this_station_name, + self.cfg.log_dir, + test_name=params["name"], + ) try: for cue in cues: diff --git a/tests/test_log.py b/tests/test_log.py index 33122e7..771f903 100644 --- a/tests/test_log.py +++ b/tests/test_log.py @@ -35,3 +35,16 @@ def test_tsv_logger_creates_log_dir(tmp_path): logger.close() assert sub.is_dir() assert logger.path.exists() + + +def test_tsv_logger_filename_includes_test_name(tmp_path): + logger = TsvLogger("A", tmp_path, test_name="run42") + logger.close() + assert logger.path.name.startswith("run42-A-") + assert logger.path.name.endswith(".tsv") + + +def test_tsv_logger_filename_without_test_name(tmp_path): + logger = TsvLogger("A", tmp_path) + logger.close() + assert logger.path.name.startswith("A-")