Skip to content

logger

write_log(logtype, target, runid, timestamp, runname, queue)

Logs job data depending on the log type.

Source code in hpcman/queue/logger.py
def write_log(logtype: LogType, target: Path, runid: str, timestamp: str, runname: Path, queue: Optional[str]) -> None:
    """Logs job data depending on the log type."""
    if logtype is LogType.FILE:
        loginfo = {runid: {"runname": runname.as_posix(), "timestamp": timestamp}}
        with target.open("at") as logfile:
            logfile.write(f"{json.dumps(loginfo, separators=(',', ':'))}\n")
    elif logtype is LogType.DB:
        target.expanduser().parent.mkdir(parents=True, exist_ok=True)
        loginfodb = {
            "runname": runname.absolute().resolve().as_posix(),
            "timestamp": timestamp,
            "wd": "",
            "queue": queue,
        }
        env = lmdb.open(target.expanduser().as_posix().encode())
        with env.begin(write=True) as txn:
            txn.put(runid.encode(), json.dumps(loginfodb, separators=(",", ":")).encode())