From 6084e2591a46b3b6feb5dc09bb97859e8ed4fb34 Mon Sep 17 00:00:00 2001 From: Ben Xu Date: Mon, 30 Dec 2024 15:17:40 -0500 Subject: [PATCH] refactor logging outside logic --- software/source/server/livekit/logger.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 software/source/server/livekit/logger.py diff --git a/software/source/server/livekit/logger.py b/software/source/server/livekit/logger.py new file mode 100644 index 0000000..1fb00c4 --- /dev/null +++ b/software/source/server/livekit/logger.py @@ -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")