This commit is contained in:
alorig
2025-11-09 23:50:19 +05:00
parent 98e900da73
commit bee6a68718
5 changed files with 96 additions and 79 deletions

View File

@@ -238,12 +238,15 @@ class ConsoleStepTracker:
self.current_phase = None
# Debug: Verify DEBUG_MODE is enabled
import sys
if DEBUG_MODE:
print(f"[DEBUG] ConsoleStepTracker initialized for '{function_name}' - DEBUG_MODE is ENABLED", flush=True)
logger.info(f"ConsoleStepTracker initialized for '{function_name}' - DEBUG_MODE is ENABLED")
init_msg = f"[DEBUG] ConsoleStepTracker initialized for '{function_name}' - DEBUG_MODE is ENABLED"
logger.info(init_msg)
print(init_msg, flush=True, file=sys.stdout)
else:
print(f"[WARNING] ConsoleStepTracker initialized for '{function_name}' - DEBUG_MODE is DISABLED", flush=True)
logger.warning(f"ConsoleStepTracker initialized for '{function_name}' - DEBUG_MODE is DISABLED")
init_msg = f"[WARNING] ConsoleStepTracker initialized for '{function_name}' - DEBUG_MODE is DISABLED"
logger.warning(init_msg)
print(init_msg, flush=True, file=sys.stdout)
def _log(self, phase: str, message: str, status: str = 'info'):
"""Internal logging method that checks DEBUG_MODE"""
@@ -256,15 +259,17 @@ class ConsoleStepTracker:
if status == 'error':
log_msg = f"[{timestamp}] [{self.function_name}] [{phase_label}] [ERROR] {message}"
# Use logger.error for errors so they're always visible
logger.error(log_msg)
elif status == 'success':
log_msg = f"[{timestamp}] [{self.function_name}] [{phase_label}] ✅ {message}"
logger.info(log_msg)
else:
log_msg = f"[{timestamp}] [{self.function_name}] [{phase_label}] {message}"
logger.info(log_msg)
# Print and flush immediately to ensure console output
print(log_msg, flush=True)
# Also log to Python logger for better visibility
logger.info(log_msg)
# Also print to stdout for immediate visibility (works in Celery worker logs)
print(log_msg, flush=True, file=sys.stdout)
self.steps.append({
'timestamp': timestamp,
@@ -300,8 +305,9 @@ class ConsoleStepTracker:
self._log('DONE', f"{message} (Duration: {duration:.2f}s)", status='success')
if DEBUG_MODE:
import sys
print(f"[{self.function_name}] === AI Task Complete ===", flush=True)
logger.info(f"[{self.function_name}] === AI Task Complete ===")
complete_msg = f"[{self.function_name}] === AI Task Complete ==="
logger.info(complete_msg)
print(complete_msg, flush=True, file=sys.stdout)
def error(self, error_type: str, message: str, exception: Exception = None):
"""Log error with standardized format"""
@@ -312,9 +318,10 @@ class ConsoleStepTracker:
if DEBUG_MODE and exception:
import sys
import traceback
print(f"[{self.function_name}] [ERROR] Stack trace:", flush=True)
traceback.print_exc()
logger.error(f"[{self.function_name}] [ERROR] Stack trace:", exc_info=exception)
error_trace_msg = f"[{self.function_name}] [ERROR] Stack trace:"
logger.error(error_trace_msg, exc_info=exception)
print(error_trace_msg, flush=True, file=sys.stdout)
traceback.print_exc(file=sys.stdout)
def retry(self, attempt: int, max_attempts: int, reason: str = ""):
"""Log retry attempt"""