2023-08-18 06:02:01 +00:00
|
|
|
from os import PathLike
|
2023-08-18 11:09:30 +00:00
|
|
|
from pathlib import Path
|
|
|
|
from typing import Optional, Union
|
2023-08-18 06:02:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VwLogger:
|
|
|
|
def __init__(self, path: Optional[Union[str, PathLike]]):
|
|
|
|
self.path = Path(path) if path else None
|
|
|
|
if self.path:
|
|
|
|
self.path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
2023-08-28 10:58:33 +00:00
|
|
|
def log(self, vw_ex: str) -> None:
|
2023-08-18 06:02:01 +00:00
|
|
|
if self.path:
|
|
|
|
with open(self.path, "a") as f:
|
|
|
|
f.write(f"{vw_ex}\n\n")
|
|
|
|
|
2023-08-28 10:58:33 +00:00
|
|
|
def logging_enabled(self) -> bool:
|
2023-08-18 06:02:01 +00:00
|
|
|
return bool(self.path)
|