refactor logging outside logic

This commit is contained in:
Ben Xu 2024-12-30 15:17:40 -05:00
parent 095b704da4
commit 6084e2591a
1 changed files with 14 additions and 0 deletions

View File

@ -0,0 +1,14 @@
import os
from datetime import datetime
# Define the path to the log file
LOG_FILE_PATH = 'worker.txt'
DEBUG = os.getenv('DEBUG', 'false').lower() == 'true'
def log_message(message: str):
"""Append a message to the log file with a timestamp."""
if not DEBUG:
return
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
with open(LOG_FILE_PATH, 'a') as log_file:
log_file.write(f"{timestamp} - {message}\n")