Spaces:
Sleeping
Sleeping
Sonu Prasad commited on
Commit ·
cb69ed9
1
Parent(s): 386dd15
Fixed logging: added print with flush=True for immediate HuggingFace output
Browse files
app.py
CHANGED
|
@@ -49,16 +49,24 @@ state_lock = threading.Lock()
|
|
| 49 |
|
| 50 |
|
| 51 |
def add_log(message: str):
|
| 52 |
-
"""Add a log message to the buffer."""
|
| 53 |
with log_lock:
|
| 54 |
timestamp = time.strftime("%H:%M:%S")
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
|
| 58 |
def log_callback(message: str):
|
| 59 |
"""Callback for bot to send logs to buffer."""
|
| 60 |
add_log(message)
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
|
| 64 |
def state_callback(state_update: dict):
|
|
|
|
| 49 |
|
| 50 |
|
| 51 |
def add_log(message: str):
|
| 52 |
+
"""Add a log message to the buffer AND print to stdout immediately."""
|
| 53 |
with log_lock:
|
| 54 |
timestamp = time.strftime("%H:%M:%S")
|
| 55 |
+
formatted = f"[{timestamp}] {message}"
|
| 56 |
+
log_buffer.append(formatted)
|
| 57 |
+
# Print immediately to stdout for HuggingFace container logs
|
| 58 |
+
print(formatted, flush=True)
|
| 59 |
|
| 60 |
|
| 61 |
def log_callback(message: str):
|
| 62 |
"""Callback for bot to send logs to buffer."""
|
| 63 |
add_log(message)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def print_log(message: str):
|
| 67 |
+
"""Direct print to stdout with flush for critical logs."""
|
| 68 |
+
timestamp = time.strftime("%H:%M:%S")
|
| 69 |
+
print(f"[{timestamp}] {message}", flush=True)
|
| 70 |
|
| 71 |
|
| 72 |
def state_callback(state_update: dict):
|
bot.py
CHANGED
|
@@ -62,6 +62,11 @@ class PracticeFusionBot:
|
|
| 62 |
|
| 63 |
def log(self, message: str, level: str = "INFO"):
|
| 64 |
"""Log message and send to callback if available."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
if level == "INFO":
|
| 66 |
self.logger.info(message)
|
| 67 |
elif level == "WARNING":
|
|
|
|
| 62 |
|
| 63 |
def log(self, message: str, level: str = "INFO"):
|
| 64 |
"""Log message and send to callback if available."""
|
| 65 |
+
# Always print immediately for HuggingFace container logs
|
| 66 |
+
import time
|
| 67 |
+
timestamp = time.strftime("%H:%M:%S")
|
| 68 |
+
print(f"[{timestamp}] [{level}] {message}", flush=True)
|
| 69 |
+
|
| 70 |
if level == "INFO":
|
| 71 |
self.logger.info(message)
|
| 72 |
elif level == "WARNING":
|