From 9a612ab7269763eb83656e39cd8d0d5d41a2ecca Mon Sep 17 00:00:00 2001 From: oedokumaci Date: Mon, 5 Feb 2024 22:01:19 +0300 Subject: [PATCH] feat: add input_log_file_name param for init_logger --- src/template_python/utils.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/template_python/utils.py b/src/template_python/utils.py index fe137f6..04409a5 100644 --- a/src/template_python/utils.py +++ b/src/template_python/utils.py @@ -13,15 +13,21 @@ # Define function to initialize the logger -def init_logger(log_to_file: bool = True) -> None: +def init_logger( + input_log_file_name: str | None = None, log_to_file: bool = True +) -> None: """Initialize the logger. Args: - file_name (str): The name of the log file. + input_log_file_name (str | None): The name of the log file. Defaults to None. + log_to_file (bool, optional): Whether to log to file. Defaults to True. """ if log_to_file: # Set the log file path and create it if it does not exist - log_file_name: str = f"logs_{datetime.now().strftime('%Y-%m-%d')}.log" + if input_log_file_name: + log_file_name: str = input_log_file_name + else: + log_file_name = f"logs_{datetime.now().strftime('%Y-%m-%d')}.log" log_file: Path = LOGS_DIR / log_file_name log_file.touch(exist_ok=True)