Skip to content

Commit

Permalink
Avoid no such file or directory in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rukasudev committed Jul 24, 2024
1 parent ae39c4b commit e06e6d5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,13 @@ def start(self) -> None:
)

def set_timed_rotating_file_handler(self) -> CustomTimedRotatingFileHandler:
log_directory = "./logs"

if not os.path.exists(log_directory):
os.makedirs(log_directory)

self.file_handler = CustomTimedRotatingFileHandler(
"./logs/keiko_log.log", when="MIDNIGHT", encoding="utf-8"
f"{log_directory}/keiko_log.log", when="MIDNIGHT", encoding="utf-8"
)
self.file_handler.suffix = "%Y_%m_%d"
self.file_handler.namer = lambda name: name.replace(".log.", "_") + ".log"
Expand Down

0 comments on commit e06e6d5

Please sign in to comment.