Files changed (1) hide show
  1. app.py +32 -0
app.py CHANGED
@@ -17,6 +17,38 @@ from datetime import datetime
17
  import re
18
  from typing import Dict, List, Tuple
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  # === Configuration ===
21
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
22
  embedding_model = "models/embedding-001"
 
17
  import re
18
  from typing import Dict, List, Tuple
19
 
20
+ import logging
21
+ import traceback
22
+ import sys
23
+
24
+ # ===== Configure Logging =====
25
+ logging.basicConfig(
26
+ filename="app.log", # All logs will be saved here
27
+ level=logging.INFO, # Change to DEBUG for more detail
28
+ format="%(asctime)s - %(levelname)s - %(message)s"
29
+ )
30
+
31
+ # ===== Capture Uncaught Exceptions =====
32
+ def log_exception(exc_type, exc_value, exc_traceback):
33
+ if issubclass(exc_type, KeyboardInterrupt):
34
+ return # Don't log keyboard interrupts
35
+ logging.critical("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
36
+
37
+ sys.excepthook = log_exception
38
+
39
+ # ===== Optional: Log that the app started =====
40
+ logging.info("App started successfully.")
41
+
42
+ # ===== Example: Use logging inside try/except =====
43
+ def example_function():
44
+ try:
45
+ result = 1 / 0 # Intentional error
46
+ except Exception as e:
47
+ logging.error("Error in example_function: %s", e)
48
+ logging.error(traceback.format_exc())
49
+
50
+ logging.info("Test log entry to check logger")
51
+
52
  # === Configuration ===
53
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
54
  embedding_model = "models/embedding-001"