feat | 添加自动格式化文件名的功能
This commit is contained in:
parent
987631c0f3
commit
a4e63ef73f
@ -115,6 +115,7 @@ class FileCacheOutputStream(BaseOutputStream):
|
|||||||
flush_timer: Optional[threading.Timer] = None
|
flush_timer: Optional[threading.Timer] = None
|
||||||
|
|
||||||
file_path: Path = Path("./logs")
|
file_path: Path = Path("./logs")
|
||||||
|
# if contain {time} -> time.strftime("%Y-%m-%d %H-%M-%S", time.gmtime(time.time)
|
||||||
file_name: str
|
file_name: str
|
||||||
# file mode: always 'a'
|
# file mode: always 'a'
|
||||||
file_encoding: str = "utf-8"
|
file_encoding: str = "utf-8"
|
||||||
@ -138,9 +139,17 @@ class FileCacheOutputStream(BaseOutputStream):
|
|||||||
file_swap_on_both: bool = False # swap file when both size and time limit reached
|
file_swap_on_both: bool = False # swap file when both size and time limit reached
|
||||||
|
|
||||||
def init(self, **kwargs) -> bool:
|
def init(self, **kwargs) -> bool:
|
||||||
|
# 时间取整
|
||||||
self.file_start_time = round(time.time())
|
self.file_start_time = round(time.time())
|
||||||
|
# 初始化文件名
|
||||||
|
if "{time}" in self.file_name:
|
||||||
|
self.file_name = self.file_name.format(time=time.strftime(
|
||||||
|
"%Y-%m-%d %H-%M-%S", time.gmtime(self.file_start_time)
|
||||||
|
))
|
||||||
|
# 初始化缓存
|
||||||
if self.text_cache is None:
|
if self.text_cache is None:
|
||||||
self.text_cache = io.StringIO()
|
self.text_cache = io.StringIO()
|
||||||
|
# 检查文件名
|
||||||
self.get_file_path()
|
self.get_file_path()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -224,8 +233,7 @@ class FileCacheOutputStream(BaseOutputStream):
|
|||||||
if file_time > self.file_time_limit:
|
if file_time > self.file_time_limit:
|
||||||
time_pass = False
|
time_pass = False
|
||||||
if (self.file_swap_on_both and size_pass and time_pass) or (
|
if (self.file_swap_on_both and size_pass and time_pass) or (
|
||||||
not self.file_swap_on_both and (size_pass or time_pass)
|
not self.file_swap_on_both and (size_pass or time_pass)):
|
||||||
):
|
|
||||||
# 两个都满足
|
# 两个都满足
|
||||||
# 或者只有一个满足
|
# 或者只有一个满足
|
||||||
if size_pass and time_pass:
|
if size_pass and time_pass:
|
||||||
@ -243,6 +251,7 @@ class FileCacheOutputStream(BaseOutputStream):
|
|||||||
if text == "":
|
if text == "":
|
||||||
return None
|
return None
|
||||||
current_file = self.check_flush()
|
current_file = self.check_flush()
|
||||||
|
# 检查文件是否存在
|
||||||
if not current_file.exists():
|
if not current_file.exists():
|
||||||
current_file.parent.mkdir(parents=True, exist_ok=True)
|
current_file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
current_file.touch(exist_ok=True)
|
current_file.touch(exist_ok=True)
|
||||||
|
@ -13,4 +13,13 @@ nuitka_config_type = Dict[str, Union[str, bool, List[Union[str, tuple]]]]
|
|||||||
raw_config_type = Dict[str, Union[nuitka_config_type, str]]
|
raw_config_type = Dict[str, Union[nuitka_config_type, str]]
|
||||||
parse_config_function = Callable[[raw_config_type], nuitka_config_type]
|
parse_config_function = Callable[[raw_config_type], nuitka_config_type]
|
||||||
|
|
||||||
__all__ = ["reader", "compile", "raw_config_type", "parse_config_function", "nuitka_config_type"]
|
# fmt: off
|
||||||
|
__all__ = [
|
||||||
|
"reader",
|
||||||
|
"compile",
|
||||||
|
"raw_config_type",
|
||||||
|
"parse_config_function",
|
||||||
|
"nuitka_config_type"
|
||||||
|
]
|
||||||
|
# fmt: on
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user