Add time folder to logs(without time of the build)

This commit is contained in:
Kiryl
2022-10-26 16:22:10 +03:00
parent 9704fabff0
commit b0e5c0334b
2 changed files with 9 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import os
import time
import logging
from typing import Union
@@ -51,12 +52,17 @@ class BookLogger:
self.main_logger = main_logger
self.logger = logging.getLogger(name)
self.logger.propagate = False
folder_path = os.path.dirname(
os.path.dirname(os.path.abspath(__file__)))
folder_path = os.path.dirname(folder_path)
filename = f"logs/{book_id}.log"
folder_path = os.path.join(os.path.dirname(folder_path), f"logs/{time.strftime('%d-%m-%Y_%H-00')}/")
filename = f"{book_id}.log"
file_path = os.path.join(folder_path, filename)
if not os.path.exists(folder_path):
os.makedirs(folder_path + time.strftime("%Y-%m-%_%H"))
file_handler = logging.FileHandler(file_path, mode=filemode)
file_format = logging.Formatter(logging_format)
file_handler.setFormatter(file_format)
self.logger.addHandler(file_handler)