Spaces:
Sleeping
Sleeping
Update logger.py
Browse files
logger.py
CHANGED
|
@@ -1,19 +1,26 @@
|
|
| 1 |
import datetime
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
def log_message(message: str):
|
| 7 |
"""
|
| 8 |
บันทึกข้อความลงในไฟล์ LOG_FILE โดยจะสร้างไฟล์ใหม่ถ้ายังไม่มี
|
| 9 |
พร้อมแนบ timestamp ปัจจุบันในแต่ละบรรทัด
|
| 10 |
"""
|
| 11 |
-
# ถ้า
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
if not os.path.exists(LOG_FILE):
|
| 13 |
with open(LOG_FILE, "w", encoding="utf-8") as f:
|
| 14 |
f.write("==== Processing Time Logs ====\n")
|
| 15 |
-
|
| 16 |
# บันทึก log พร้อมวันที่-เวลา
|
| 17 |
with open(LOG_FILE, "a", encoding="utf-8") as f:
|
| 18 |
current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 19 |
f.write(f"[{current_time}] {message}\n")
|
|
|
|
|
|
| 1 |
import datetime
|
| 2 |
import os
|
| 3 |
|
| 4 |
+
# กำหนด path สำหรับ log file ให้ตรงกับ persistent storage
|
| 5 |
+
LOG_FILE = "/app/logs/processing_logs.txt"
|
| 6 |
|
| 7 |
def log_message(message: str):
|
| 8 |
"""
|
| 9 |
บันทึกข้อความลงในไฟล์ LOG_FILE โดยจะสร้างไฟล์ใหม่ถ้ายังไม่มี
|
| 10 |
พร้อมแนบ timestamp ปัจจุบันในแต่ละบรรทัด
|
| 11 |
"""
|
| 12 |
+
# ถ้าโฟลเดอร์ที่เก็บ log ยังไม่มี ให้สร้างขึ้น
|
| 13 |
+
log_dir = os.path.dirname(LOG_FILE)
|
| 14 |
+
if not os.path.exists(log_dir):
|
| 15 |
+
os.makedirs(log_dir, exist_ok=True)
|
| 16 |
+
|
| 17 |
+
# ถ้าไฟล์ log ยังไม่มี ให้สร้างไฟล์ใหม่พร้อมเขียนหัวข้อ
|
| 18 |
if not os.path.exists(LOG_FILE):
|
| 19 |
with open(LOG_FILE, "w", encoding="utf-8") as f:
|
| 20 |
f.write("==== Processing Time Logs ====\n")
|
| 21 |
+
|
| 22 |
# บันทึก log พร้อมวันที่-เวลา
|
| 23 |
with open(LOG_FILE, "a", encoding="utf-8") as f:
|
| 24 |
current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 25 |
f.write(f"[{current_time}] {message}\n")
|
| 26 |
+
|