mirror of
https://github.com/hwchase17/langchain
synced 2024-11-08 07:10:35 +00:00
19 lines
516 B
Python
19 lines
516 B
Python
from os import PathLike
|
|
from pathlib import Path
|
|
from typing import Optional, Union
|
|
|
|
|
|
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)
|
|
|
|
def log(self, vw_ex: str) -> None:
|
|
if self.path:
|
|
with open(self.path, "a") as f:
|
|
f.write(f"{vw_ex}\n\n")
|
|
|
|
def logging_enabled(self) -> bool:
|
|
return bool(self.path)
|