@@ -62,21 +62,33 @@ def parse_uri(uri: str) -> Tuple[str, str]:
6262
6363class DialogChainEngine :
6464 def __init__ (self , config : Dict [str , Any ], verbose : bool = False ):
65+ # Initialize logger first
66+ self .logger = setup_logger (__name__ )
67+ self .logger .info ("🔧 Initializing DialogChainEngine" )
68+
6569 self .config = config
6670 self .verbose = verbose
6771 self .routes = config .get ("routes" , [])
6872 self .running_processes = {}
6973 self ._is_running = False
7074 self ._tasks = []
75+
76+ self .logger .info (f"🔧 Loaded { len (self .routes )} routes from config" )
77+ if self .verbose :
78+ self .logger .info (f"🔧 Verbose mode enabled" )
7179
7280 # Validate the configuration on initialization
81+ self .logger .info ("🔧 Validating configuration..." )
7382 errors = self .validate_config ()
7483 if errors :
7584 error_msg = "Invalid configuration:\n " + "\n " .join (
7685 f"- { error } " for error in errors
7786 )
87+ self .logger .error (f"❌ Configuration validation failed: { error_msg } " )
7888 raise ValueError (error_msg )
7989
90+ self .logger .info ("✅ Engine initialized successfully" )
91+
8092 @property
8193 def is_running (self ) -> bool :
8294 """Return whether the engine is currently running."""
@@ -109,7 +121,7 @@ async def start(self):
109121 await destination .connect ()
110122
111123 # Create and store task
112- task = asyncio .create_task (self .run_route (route , source , destination ))
124+ task = asyncio .create_task (self .run_route_config (route , source , destination ))
113125 self ._tasks .append (task )
114126
115127 self .log ("Engine started successfully" )
@@ -176,7 +188,7 @@ async def run_all_routes(self):
176188
177189 # Create and start task for this route
178190 task = asyncio .create_task (
179- self .run_route (route_config , source , destination )
191+ self .run_route_config (route_config , source , destination )
180192 )
181193 tasks .append (task )
182194
@@ -194,7 +206,7 @@ async def run_all_routes(self):
194206 self .log (f"Starting { len (tasks )} routes..." )
195207 await asyncio .gather (* tasks , return_exceptions = True )
196208
197- async def run_route (self , route : Dict [str , Any ], source : Source , destination : Destination ):
209+ async def run_route_config (self , route : Dict [str , Any ], source : Source , destination : Destination ):
198210 """Run a specific route with the given source and destination
199211
200212 Args:
@@ -206,8 +218,20 @@ async def run_route(self, route: Dict[str, Any], source: Source, destination: De
206218 It runs the route configuration with the provided source and destination.
207219 """
208220 route_name = route .get ("name" , "unnamed" )
221+ logger .info (f"🔧 Starting route: { route_name } " )
222+ logger .info (f"🔧 Route config: { route } " )
223+ logger .info (f"🔧 Source type: { type (source ).__name__ } " )
224+ logger .info (f"🔧 Destination type: { type (destination ).__name__ } " )
209225 self .log (f"Starting route: { route_name } " )
210226
227+ if not source :
228+ logger .error (f"❌ No source provided for route: { route_name } " )
229+ return
230+
231+ if not destination :
232+ logger .error (f"❌ No destination provided for route: { route_name } " )
233+ return
234+
211235 try :
212236 # Connect to source if not already connected
213237 if hasattr (source , 'connect' ) and callable (source .connect ) and not getattr (source , 'is_connected' , False ):
@@ -447,6 +471,49 @@ def create_destination(self, uri: str) -> Destination:
447471 return HTTPDestination (uri , ** config )
448472 elif scheme == "file" :
449473 return FileDestination (path , ** config )
474+ elif scheme == "log" :
475+ # Handle log destination (e.g., log:info, log:error)
476+ log_level = path .upper () if path else "INFO"
477+
478+ # Create a simple destination that logs messages
479+ class LogDestination :
480+ def __init__ (self , level ):
481+ self .level = level
482+ self .sent_messages = []
483+
484+ async def send (self , message ):
485+ log_message = f"[Log Destination] { message } "
486+ if self .level == "DEBUG" :
487+ self .logger .debug (log_message )
488+ elif self .level == "INFO" :
489+ self .logger .info (log_message )
490+ elif self .level == "WARNING" :
491+ self .logger .warning (log_message )
492+ elif self .level == "ERROR" :
493+ self .logger .error (log_message )
494+ elif self .level == "CRITICAL" :
495+ self .logger .critical (log_message )
496+ else :
497+ self .logger .info (log_message ) # Default to info
498+
499+ # Store the message for testing/verification
500+ self .sent_messages .append (message )
501+ return True
502+
503+ async def connect (self ):
504+ pass
505+
506+ async def disconnect (self ):
507+ pass
508+
509+ async def __aenter__ (self ):
510+ return self
511+
512+ async def __aexit__ (self , exc_type , exc_val , exc_tb ):
513+ pass
514+
515+ return LogDestination (log_level )
516+
450517 elif scheme == "mock" :
451518 # For testing purposes
452519 from unittest .mock import AsyncMock
0 commit comments