|
@@ -1,6 +1,8 @@
|
|
|
import pathlib
|
|
import pathlib
|
|
|
import time
|
|
import time
|
|
|
|
|
|
|
|
|
|
+from .file_handler import file_handler
|
|
|
|
|
+
|
|
|
class log_directory:
|
|
class log_directory:
|
|
|
def __init__(self, target: pathlib.Path | None = None) -> None:
|
|
def __init__(self, target: pathlib.Path | None = None) -> None:
|
|
|
if target is None:
|
|
if target is None:
|
|
@@ -27,6 +29,30 @@ class log_directory:
|
|
|
for count in self.__root.iterdir():
|
|
for count in self.__root.iterdir():
|
|
|
if self._ends_with(count.name, ".log"):
|
|
if self._ends_with(count.name, ".log"):
|
|
|
yield self.__root / count
|
|
yield self.__root / count
|
|
|
|
|
+
|
|
|
|
|
+ def get_logs_for_day(self, name: str | None = None) -> tuple:
|
|
|
|
|
+ if name is None:
|
|
|
|
|
+ name = self._base_name
|
|
|
|
|
+
|
|
|
|
|
+ logs = self.iter_logs()
|
|
|
|
|
+ filtered = filter(lambda count: count.find(name) != -1, logs)
|
|
|
|
|
+
|
|
|
|
|
+ return tuple(filtered)
|
|
|
|
|
+
|
|
|
|
|
+ @property
|
|
|
|
|
+ def _base_name(self) -> str:
|
|
|
|
|
+ return time.strftime("%Y-%m-%d", time.now())
|
|
|
|
|
|
|
|
|
|
+ def _get_new_name(self) -> str:
|
|
|
|
|
+ base_name = self._base_name
|
|
|
|
|
+ logs_for_name = self.get_logs_for_day(base_name)
|
|
|
|
|
+ in_result = base_name + "-" + str(len(logs_for_name) + 1) + ".log"
|
|
|
|
|
+
|
|
|
|
|
+ return in_result
|
|
|
|
|
+
|
|
|
|
|
+ def get_new_file(self) -> pathlib.Path:
|
|
|
|
|
+ return self.root / pathlib.Path(self._get_new_name())
|
|
|
|
|
|
|
|
|
|
+ def get_new_handler(self) -> file_handler:
|
|
|
|
|
+ return file_handler(self.get_new_file)
|
|
|
|
|
|