Thiophai commited on
Commit
060411b
·
verified ·
1 Parent(s): 37c246a

Update logger.py

Browse files
Files changed (1) hide show
  1. logger.py +10 -3
logger.py CHANGED
@@ -1,19 +1,26 @@
1
  import datetime
2
  import os
3
 
4
- LOG_FILE = "processing_logs.txt"
 
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
+