feat(log): ensure parent directory exists before opening log file
Signed-off-by: zhenyus <zhenyus@mathmast.com>
This commit is contained in:
parent
b8f7307a86
commit
bb90b26883
@ -17,6 +17,10 @@ class JsonSink:
|
|||||||
self._open_log_file()
|
self._open_log_file()
|
||||||
|
|
||||||
def _open_log_file(self):
|
def _open_log_file(self):
|
||||||
|
# ensure the parent directory exists
|
||||||
|
parent_dir = self.log_file_path.parent
|
||||||
|
if not parent_dir.exists():
|
||||||
|
parent_dir.mkdir(parents=True, exist_ok=True)
|
||||||
self.log_file = self.log_file_path.open("a", encoding="utf-8")
|
self.log_file = self.log_file_path.open("a", encoding="utf-8")
|
||||||
|
|
||||||
def _should_rotate(self) -> bool:
|
def _should_rotate(self) -> bool:
|
||||||
|
|||||||
@ -17,6 +17,10 @@ class JsonSink:
|
|||||||
self._open_log_file()
|
self._open_log_file()
|
||||||
|
|
||||||
def _open_log_file(self):
|
def _open_log_file(self):
|
||||||
|
# ensure the parent directory exists
|
||||||
|
parent_dir = self.log_file_path.parent
|
||||||
|
if not parent_dir.exists():
|
||||||
|
parent_dir.mkdir(parents=True, exist_ok=True)
|
||||||
self.log_file = self.log_file_path.open("a", encoding="utf-8")
|
self.log_file = self.log_file_path.open("a", encoding="utf-8")
|
||||||
|
|
||||||
def _should_rotate(self) -> bool:
|
def _should_rotate(self) -> bool:
|
||||||
|
|||||||
@ -17,6 +17,10 @@ class JsonSink:
|
|||||||
self._open_log_file()
|
self._open_log_file()
|
||||||
|
|
||||||
def _open_log_file(self):
|
def _open_log_file(self):
|
||||||
|
# ensure the parent directory exists
|
||||||
|
parent_dir = self.log_file_path.parent
|
||||||
|
if not parent_dir.exists():
|
||||||
|
parent_dir.mkdir(parents=True, exist_ok=True)
|
||||||
self.log_file = self.log_file_path.open("a", encoding="utf-8")
|
self.log_file = self.log_file_path.open("a", encoding="utf-8")
|
||||||
|
|
||||||
def _should_rotate(self) -> bool:
|
def _should_rotate(self) -> bool:
|
||||||
|
|||||||
@ -17,6 +17,10 @@ class JsonSink:
|
|||||||
self._open_log_file()
|
self._open_log_file()
|
||||||
|
|
||||||
def _open_log_file(self):
|
def _open_log_file(self):
|
||||||
|
# ensure the parent directory exists
|
||||||
|
parent_dir = self.log_file_path.parent
|
||||||
|
if not parent_dir.exists():
|
||||||
|
parent_dir.mkdir(parents=True, exist_ok=True)
|
||||||
self.log_file = self.log_file_path.open("a", encoding="utf-8")
|
self.log_file = self.log_file_path.open("a", encoding="utf-8")
|
||||||
|
|
||||||
def _should_rotate(self) -> bool:
|
def _should_rotate(self) -> bool:
|
||||||
|
|||||||
@ -17,6 +17,10 @@ class JsonSink:
|
|||||||
self._open_log_file()
|
self._open_log_file()
|
||||||
|
|
||||||
def _open_log_file(self):
|
def _open_log_file(self):
|
||||||
|
# ensure the parent directory exists
|
||||||
|
parent_dir = self.log_file_path.parent
|
||||||
|
if not parent_dir.exists():
|
||||||
|
parent_dir.mkdir(parents=True, exist_ok=True)
|
||||||
self.log_file = self.log_file_path.open("a", encoding="utf-8")
|
self.log_file = self.log_file_path.open("a", encoding="utf-8")
|
||||||
|
|
||||||
def _should_rotate(self) -> bool:
|
def _should_rotate(self) -> bool:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user