From 2519e175f449b0c46c029fcdff3b9ccca6444cc4 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Mon, 1 Apr 2024 12:10:29 +0530 Subject: [PATCH 1/5] Add all log files to `.gitignore` --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 06d6f078..00990e07 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,10 @@ database/automod.json database/isobank/* *.log *.pyc +logs/currency.log +logs/error-log.txt +logs/info-log.txt +logs/startup-log.txt __pycache__ *.bak venv From a5ba0fe23f630ad2bef6e6b6d1d5457a3952bd04 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Mon, 1 Apr 2024 12:12:17 +0530 Subject: [PATCH 2/5] Remove all log files from project directory --- logs/currency.log | 0 logs/error-log.txt | 1 - logs/info-log.txt | 1 - logs/startup-log.txt | 0 4 files changed, 2 deletions(-) delete mode 100644 logs/currency.log delete mode 100644 logs/error-log.txt delete mode 100644 logs/info-log.txt delete mode 100644 logs/startup-log.txt diff --git a/logs/currency.log b/logs/currency.log deleted file mode 100644 index e69de29b..00000000 diff --git a/logs/error-log.txt b/logs/error-log.txt deleted file mode 100644 index 7809b0e7..00000000 --- a/logs/error-log.txt +++ /dev/null @@ -1 +0,0 @@ -#All exceptions will be logged here! diff --git a/logs/info-log.txt b/logs/info-log.txt deleted file mode 100644 index d129abca..00000000 --- a/logs/info-log.txt +++ /dev/null @@ -1 +0,0 @@ -#All information and warnings will be logged here! diff --git a/logs/startup-log.txt b/logs/startup-log.txt deleted file mode 100644 index e69de29b..00000000 From 960df47b2d562c285e04f40c8a0e7c6b6104c5f8 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Mon, 1 Apr 2024 12:14:59 +0530 Subject: [PATCH 3/5] Add automatic log creation for `startup-log` --- main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.py b/main.py index 47109320..93a57332 100644 --- a/main.py +++ b/main.py @@ -55,6 +55,10 @@ def initial_setup(): open('logs/currency.log', 'x', encoding="utf-8") logger.info("Created currency log", module="main/Setup", nolog=True) time.sleep(0.5) + if not os.path.isfile("logs/startup-log.txt"): + with open("logs/startup-log.txt", 'x', encoding="utf-8") as this: + this.close() + time.sleep(0.5) except IOError as e: logger.error(f"Failed to make log file: {e}", module="main/Setup", nolog=True) # Framework Module Loader From 1c7b2279ee879c829b92d2eecd1f2fdfc4313609 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Mon, 1 Apr 2024 12:16:21 +0530 Subject: [PATCH 4/5] Move `initial_setup()` to right after definition to avoid file conflicts --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index 93a57332..5116f256 100644 --- a/main.py +++ b/main.py @@ -61,6 +61,8 @@ def initial_setup(): time.sleep(0.5) except IOError as e: logger.error(f"Failed to make log file: {e}", module="main/Setup", nolog=True) +initial_setup() # Check for any missing sub-directories or databases in bot directory + # Framework Module Loader colors = colors.Colors() s = logger.StartupLog("logs/startup-log.txt", clear_old_logs=True) From 371fa5d1b68a9b17d2f50ce99e0923bcc623e140 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Mon, 1 Apr 2024 12:18:24 +0530 Subject: [PATCH 5/5] Close file streams after log file creation to avoid denied log write permissions --- main.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 5116f256..eda162f6 100644 --- a/main.py +++ b/main.py @@ -44,15 +44,20 @@ def initial_setup(): except IOError as e: logger.error(f"Failed to make database file: {e}", module="main/Setup") try: if not os.path.isfile("logs/info-log.txt"): - open('logs/info-log.txt', 'x', encoding="utf-8") + with open('logs/info-log.txt', 'x', encoding="utf-8") as this: + this.write("#All information and warnings will be logged here!\n") + this.close() logger.info("Created info log", module="main/Setup", nolog=True) time.sleep(0.5) if not os.path.isfile("logs/error-log.txt"): - open('logs/error-log.txt', 'x', encoding="utf-8") + with open('logs/error-log.txt', 'x', encoding="utf-8") as this: + this.write("#All exceptions will be logged here!\n") + this.close() logger.info("Created error log", module="main/Setup", nolog=True) time.sleep(0.5) if not os.path.isfile("logs/currency.log"): - open('logs/currency.log', 'x', encoding="utf-8") + with open('logs/currency.log', 'x', encoding="utf-8") as this: + this.close() logger.info("Created currency log", module="main/Setup", nolog=True) time.sleep(0.5) if not os.path.isfile("logs/startup-log.txt"): @@ -385,7 +390,6 @@ async def credits(ctx: ApplicationContext): await ctx.respond(embed=localembed) # Initialization -initial_setup() # Check for any missing sub-directories or databases in bot directory active_cogs = [ "economy", "maths",