Skip to content

taps.record

Record module-attribute

Record: TypeAlias = Dict[str, Any]

Record type.

RecordLogger

Bases: Protocol

Record logger protocol.

log

log(record: Record) -> None

Log a record.

Source code in taps/record.py
def log(self, record: Record) -> None:
    """Log a record."""
    ...

close

close() -> None

Close the logger.

Source code in taps/record.py
def close(self) -> None:
    """Close the logger."""
    ...

JSONRecordLogger

JSONRecordLogger(filepath: Path | str)

JSON lines record logger.

Logs records as JSON strings per line to a file.

Parameters:

  • filepath (Path | str) –

    Filepath to log to.

Source code in taps/record.py
def __init__(self, filepath: pathlib.Path | str) -> None:
    self._filepath = pathlib.Path(filepath)
    self._handle = open(self._filepath, 'a')  # noqa: SIM115

log

log(record: Record) -> None

Log a record.

Source code in taps/record.py
def log(self, record: Record) -> None:
    """Log a record."""
    self._handle.write(json.dumps(record) + '\n')

close

close() -> None

Close the logger.

Source code in taps/record.py
def close(self) -> None:
    """Close the logger."""
    self._handle.close()

NullRecordLogger

Null/no-op record logger.

log

log(record: Record) -> None

Log a record.

Source code in taps/record.py
def log(self, record: Record) -> None:
    """Log a record."""
    return

close

close() -> None

Close the logger.

Source code in taps/record.py
def close(self) -> None:
    """Close the logger."""
    return