Merged PR 2899: Create .anaxi folder automatically if it does not exist

This PR ensures that the logger sets up automatically in case the folder does not exists.
It just checks if the directory exists, and if it does not exist, it just creates the .anaxi folder.

Checked in local by dropping the folder and works well.
This commit is contained in:
Oriol Roqué Paniagua 2024-09-18 12:22:25 +00:00 committed by Pablo Martín
commit 12299602e4

View file

@ -1,4 +1,5 @@
import logging
import os
from anaxi.constants import PATHS
@ -14,6 +15,9 @@ def get_anaxi_logger(name: str) -> None:
console_handler.setFormatter(anaxi_formatter)
logger.addHandler(console_handler)
if not os.path.exists(os.path.dirname(PATHS.logging_file)):
os.makedirs(os.path.dirname(PATHS.logging_file))
file_handler = logging.FileHandler(filename=PATHS.logging_file)
file_handler.setFormatter(anaxi_formatter)
logger.addHandler(file_handler)