1313if _ENV_FILE .exists ():
1414 load_dotenv (_ENV_FILE )
1515
16+ from main_chat .data_ingestion .utils .log_util import log , log_error , log_info , log_success , log_warning
17+
1618# ============================================================================
1719# Environment Detection
1820# ============================================================================
@@ -113,7 +115,7 @@ def _env(key: str, default: str = "") -> str:
113115 try :
114116 DATA_DOWNLOAD_DIR .mkdir (parents = True , exist_ok = True )
115117 except Exception as e :
116- print (f"Warning: Could not create DATA_DOWNLOAD_DIR '{ DATA_DOWNLOAD_DIR } ': { e } " )
118+ log_error (f"Could not create DATA_DOWNLOAD_DIR '{ DATA_DOWNLOAD_DIR } ': { e } " )
117119
118120SYNC_STATE_FILE = DATA_DOWNLOAD_DIR / ".sync_state_gdrive.json"
119121EMAIL_SYNC_STATE_FILE = DATA_DOWNLOAD_DIR / ".sync_state_gmail.json"
@@ -258,7 +260,7 @@ def get_response_text(response):
258260 if hasattr (response , "candidates" ) and response .candidates :
259261 if response .candidates [0 ].content .parts :
260262 return response .candidates [0 ].content .parts [0 ].text
261- print ( "Warning: Empty model response" )
263+ log_warning ( " Empty model response" )
262264 return ""
263265
264266
@@ -310,7 +312,7 @@ def validate_config(test_connections: bool = True) -> list:
310312 if not path .exists ():
311313 try :
312314 path .mkdir (parents = True , exist_ok = True )
313- print (f" ✔ Created { name } : { path } " )
315+ log_success (f"Created { name } : { path } " )
314316 except Exception as e :
315317 errors .append (f"Cannot create { name } '{ path } ': { e } " )
316318 elif not os .access (path , os .W_OK ):
@@ -322,7 +324,7 @@ def validate_config(test_connections: bool = True) -> list:
322324
323325 # Test connections (if requested)
324326 if test_connections :
325- print ("Testing connections..." )
327+ log_info ("Testing connections..." )
326328
327329 # Test Google Drive connection
328330 gdrive_error = _test_google_drive_connection ()
@@ -349,9 +351,9 @@ def validate_config(test_connections: bool = True) -> list:
349351
350352 # Print warnings (non-fatal)
351353 if warnings :
352- print ( " \n ⚠ Configuration Warnings:" )
354+ log_warning ( " Configuration Warnings:" )
353355 for warning in warnings :
354- print (f" - { warning } " )
356+ log_warning (f" { warning } " )
355357
356358 return errors
357359
@@ -373,7 +375,7 @@ def _test_google_drive_connection() -> Optional[str]:
373375 # Try to get folder metadata (validates both auth and folder access)
374376 folder = service .files ().get (fileId = GOOGLE_DRIVE_FOLDER_ID , fields = "id, name" ).execute ()
375377
376- print (f" ✔ Google Drive: Connected to folder '{ folder .get ('name' , 'unknown' )} '" )
378+ log_success (f"Google Drive: Connected to folder '{ folder .get ('name' , 'unknown' )} '" )
377379 return None
378380
379381 except ImportError :
@@ -415,7 +417,7 @@ def _test_gmail_connection() -> Optional[str]:
415417 # Save refreshed token
416418 with open (GMAIL_TOKEN_PATH , "w" ) as token_file :
417419 token_file .write (creds .to_json ())
418- print ( " ℹ Gmail: Token refreshed" )
420+ log_info ( " Gmail: Token refreshed" )
419421 except Exception as refresh_error :
420422 return f"AUTH_REQUIRED: Token expired and refresh failed: { refresh_error } "
421423 elif creds .expired :
@@ -426,7 +428,7 @@ def _test_gmail_connection() -> Optional[str]:
426428 profile = service .users ().getProfile (userId = "me" ).execute ()
427429 email = profile .get ("emailAddress" , "unknown" )
428430
429- print (f" ✔ Gmail: Connected as { email } " )
431+ log_success (f"Gmail: Connected as { email } " )
430432 return None
431433
432434 except ImportError :
@@ -457,7 +459,7 @@ def _test_mysql_connection() -> Optional[str]:
457459 cursor .fetchone ()
458460
459461 conn .close ()
460- print (f" ✔ MySQL: Connected to { MYSQL_HOST } /{ MYSQL_DB } " )
462+ log_success (f"MySQL: Connected to { MYSQL_HOST } /{ MYSQL_DB } " )
461463 return None
462464
463465 except ImportError :
@@ -494,7 +496,7 @@ def _test_gemini_connection() -> Optional[str]:
494496 text = response .candidates [0 ].content .parts [0 ].text .strip ().lower ()
495497
496498 if text :
497- print (f" ✔ Gemini API: Model '{ GEMINI_MODEL } ' responded with: { text } " )
499+ log_success (f"Gemini API: Model '{ GEMINI_MODEL } ' responded with: { text } \n " )
498500 return None
499501 else :
500502 return "API responded but returned empty content"
@@ -515,7 +517,7 @@ def _test_gemini_connection() -> Optional[str]:
515517 return f"API key doesn't have permission for model '{ GEMINI_MODEL } '"
516518 elif "RESOURCE_EXHAUSTED" in error_msg or "429" in error_msg :
517519 # Rate limited means the key works!
518- print ( " ✔ Gemini API: Key valid (rate limited, but working)" )
520+ log_success ( " Gemini API: Key valid (rate limited, but working)" )
519521 return None
520522 elif "not found" in error_msg .lower () or "404" in error_msg :
521523 return f"Model '{ GEMINI_MODEL } ' not found - check model name"
@@ -526,46 +528,39 @@ def _test_gemini_connection() -> Optional[str]:
526528
527529
528530def print_config_summary (test_connections : bool = False ):
529- print ("=" * 80 )
530- print (f"Configuration Summary [ENVIRONMENT: { ENVIRONMENT .upper ()} ]" )
531- print ("=" * 80 )
532- print (f"Base Path: { BASE_PATH } " )
533- print ()
534- print ("Database:" )
535- print (f" MySQL Host: { MYSQL_HOST } :{ MYSQL_PORT } " )
536- print (f" MySQL DB: { MYSQL_DB } " )
537- print (f" MySQL User: { MYSQL_USER } " )
538- print ()
539- print ("AI/LLM:" )
540- print (f" Gemini Model: { GEMINI_MODEL } " )
541- print (f" Gemini Embed Model: { GEMINI_EMBED_MODEL } " )
542- print (f" Gemini API Key: { '*' * 10 } ...{ GEMINI_API_KEY [- 4 :] if GEMINI_API_KEY else 'NOT SET' } " )
543- print ()
544- print ("Google Services:" )
545- print (f" Drive Folder ID: { GOOGLE_DRIVE_FOLDER_ID or 'NOT SET' } " )
546- print (f" Drive Credentials: { GOOGLE_CREDENTIALS_PATH } " )
547- print (f" Gmail Credentials: { GMAIL_CREDENTIALS_PATH } " )
548- print (f" Gmail Token: { GMAIL_TOKEN_PATH } { '✔' if GMAIL_TOKEN_PATH and GMAIL_TOKEN_PATH .exists () else '(not found)' } " )
549- print ()
550- print ("Directories:" )
551- print (f" Vector DB: { VECTORDB_DIR } " )
552- print (f" Data Downloads: { DATA_DOWNLOAD_DIR } " )
553- print ()
554- print (f"Processing: LLM Max Workers = { LLM_MAX_WORKERS } " )
555- print ("=" * 80 )
531+ log ("=" * 80 )
532+ log (f"Configuration Summary [ENVIRONMENT: { ENVIRONMENT .upper ()} ]" )
533+ log ("=" * 80 )
534+ log (f"Base Path: { BASE_PATH } \n " )
535+ log ("Database:" )
536+ log (f" MySQL Host: { MYSQL_HOST } :{ MYSQL_PORT } " )
537+ log (f" MySQL DB: { MYSQL_DB } " )
538+ log (f" MySQL User: { MYSQL_USER } \n " )
539+ log ("AI/LLM:" )
540+ log (f" Gemini Model: { GEMINI_MODEL } " )
541+ log (f" Gemini Embed Model: { GEMINI_EMBED_MODEL } " )
542+ log (f" Gemini API Key: { '*' * 10 } ...{ GEMINI_API_KEY [- 4 :] if GEMINI_API_KEY else 'NOT SET' } \n " )
543+ log (f" Processing: LLM Max Workers = { LLM_MAX_WORKERS } " )
544+ log ("Google Services:" )
545+ log (f" Drive Folder ID: { GOOGLE_DRIVE_FOLDER_ID or 'NOT SET' } " )
546+ log (f" Drive Credentials: { GOOGLE_CREDENTIALS_PATH } " )
547+ log (f" Gmail Credentials: { GMAIL_CREDENTIALS_PATH } " )
548+ log (f" Gmail Token: { GMAIL_TOKEN_PATH } { '✔' if GMAIL_TOKEN_PATH and GMAIL_TOKEN_PATH .exists () else '(not found)' } \n " )
549+ log ("Directories:" )
550+ log (f" Vector DB: { VECTORDB_DIR } " )
551+ log (f" Data Downloads: { DATA_DOWNLOAD_DIR } \n " )
552+ log ("=" * 80 )
556553
557554 errors = validate_config (test_connections = test_connections )
558555
559556 if errors :
560- print ( " \n ✗ Configuration Errors:" )
557+ log_error ( " Configuration Errors:" )
561558 for error in errors :
562- print (f" - { error } " )
563- print ()
559+ log_error (f" { error } " )
564560 else :
565- print ( " \n ✔ Configuration valid!" )
561+ log_success ( " Configuration valid!" )
566562 if test_connections :
567- print (" All connections successful." )
568- print ()
563+ log_success ("All connections successful." )
569564
570565 return len (errors ) == 0
571566
0 commit comments