Files

32 lines
888 B
Python

import datetime
import os
from config import Config
def log(txt, wrapped=False):
try:
if not os.path.exists(Config.LOG_DIR):
os.makedirs(Config.LOG_DIR)
with open(Config.debug_log_path(), 'a') as f:
if wrapped:
f.write('==============================================\n')
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
lines = txt.split('\n')
for i, line in enumerate(lines):
prefix = f"{timestamp} - " if i == 0 else " " * \
len(timestamp) + " "
f.writelines([f"{prefix}{line}\n"])
if wrapped:
f.write('==============================================\n')
except Exception as e:
print(f"Failed to write to debug.txt: {e}")
def moveDebugLog():
deblogpath = os.path.join(Config.LOG_DIR, 'debug.txt')
if os.path.exists(Config.debug_log_path()):
os.rename(deblogpath, os.path.join(Config.LOG_DIR, 'old-debug.txt'))