From bdda886e10dbb39d77c1b7f2c90ab4e5c0264ece Mon Sep 17 00:00:00 2001 From: michael-grace Date: Sun, 8 Nov 2020 23:38:57 +0000 Subject: [PATCH] windows doesn't like the directories not existing --- .gitignore | 4 ++-- helpers/logging_manager.py | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 09936eb..b68e97c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ __pycache__/ -state/ +state/* *.egg-info/ @@ -31,7 +31,7 @@ dev/welcome.mp3 build/build-exe-pyinstaller-command.sh -logs/ +logs/* *.mp3 diff --git a/helpers/logging_manager.py b/helpers/logging_manager.py index 8df6d65..c51d4a4 100644 --- a/helpers/logging_manager.py +++ b/helpers/logging_manager.py @@ -1,5 +1,6 @@ import logging from helpers.os_environment import resolve_external_file_path +import os class LoggingManager(): @@ -9,8 +10,19 @@ class LoggingManager(): def __init__(self, name): self.logger = logging.getLogger(name) + filename: str = resolve_external_file_path("/logs/" + name + ".log") + + if not os.path.isfile(filename): + try: + # Try creating the file. + open(filename, "x") + except Exception as e: + print(e) + print("Failed to create log file") + return + logging.basicConfig( - filename=resolve_external_file_path("/logs/" + name + ".log"), + filename=filename, format='%(asctime)s | %(levelname)s | %(message)s', level=logging.INFO, filemode='a'