fg
This commit is contained in:
@@ -236,21 +236,35 @@ class ConsoleStepTracker:
|
||||
self.start_time = time.time()
|
||||
self.steps = []
|
||||
self.current_phase = None
|
||||
|
||||
# Debug: Verify DEBUG_MODE is enabled
|
||||
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")
|
||||
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")
|
||||
|
||||
def _log(self, phase: str, message: str, status: str = 'info'):
|
||||
"""Internal logging method that checks DEBUG_MODE"""
|
||||
if not DEBUG_MODE:
|
||||
return
|
||||
|
||||
import sys
|
||||
timestamp = datetime.now().strftime('%H:%M:%S')
|
||||
phase_label = phase.upper()
|
||||
|
||||
if status == 'error':
|
||||
print(f"[{timestamp}] [{self.function_name}] [{phase_label}] [ERROR] {message}")
|
||||
log_msg = f"[{timestamp}] [{self.function_name}] [{phase_label}] [ERROR] {message}"
|
||||
elif status == 'success':
|
||||
print(f"[{timestamp}] [{self.function_name}] [{phase_label}] ✅ {message}")
|
||||
log_msg = f"[{timestamp}] [{self.function_name}] [{phase_label}] ✅ {message}"
|
||||
else:
|
||||
print(f"[{timestamp}] [{self.function_name}] [{phase_label}] {message}")
|
||||
log_msg = f"[{timestamp}] [{self.function_name}] [{phase_label}] {message}"
|
||||
|
||||
# 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)
|
||||
|
||||
self.steps.append({
|
||||
'timestamp': timestamp,
|
||||
@@ -285,7 +299,9 @@ class ConsoleStepTracker:
|
||||
duration = time.time() - self.start_time
|
||||
self._log('DONE', f"{message} (Duration: {duration:.2f}s)", status='success')
|
||||
if DEBUG_MODE:
|
||||
print(f"[{self.function_name}] === AI Task Complete ===")
|
||||
import sys
|
||||
print(f"[{self.function_name}] === AI Task Complete ===", flush=True)
|
||||
logger.info(f"[{self.function_name}] === AI Task Complete ===")
|
||||
|
||||
def error(self, error_type: str, message: str, exception: Exception = None):
|
||||
"""Log error with standardized format"""
|
||||
@@ -294,9 +310,11 @@ class ConsoleStepTracker:
|
||||
error_msg += f" ({type(exception).__name__})"
|
||||
self._log(self.current_phase or 'ERROR', error_msg, status='error')
|
||||
if DEBUG_MODE and exception:
|
||||
import sys
|
||||
import traceback
|
||||
print(f"[{self.function_name}] [ERROR] Stack trace:")
|
||||
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)
|
||||
|
||||
def retry(self, attempt: int, max_attempts: int, reason: str = ""):
|
||||
"""Log retry attempt"""
|
||||
|
||||
Reference in New Issue
Block a user