log_directory.py 742 B

1234567891011121314151617181920212223242526272829303132
  1. import pathlib
  2. import time
  3. class log_directory:
  4. def __init__(self, target: pathlib.Path | None = None) -> None:
  5. if target is None:
  6. target = pathlib.Path("./logs")
  7. if not target.is_dir():
  8. target.mkdir()
  9. self.__root = target
  10. @staticmethod
  11. def _ends_with(name: str, ending: str) -> bool:
  12. return name[-len(ending):] == ending
  13. @property
  14. def root(self) -> pathlib.Path:
  15. return self.__root
  16. @property
  17. def logs(self) -> tuple:
  18. return tuple(self.iter_logs())
  19. def iter_logs(self) -> pathlib.Path:
  20. for count in self.__root.iterdir():
  21. if self._ends_with(count.name, ".log"):
  22. yield self.__root / count