Repository navigation
Expand file tree
/
Copy pathbasic_usage.py
More file actions
64 lines (51 loc) · 2.21 KB
/
Copy pathbasic_usage.py
File metadata and controls
64 lines (51 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from vibelogger import create_file_logger
def fetch_user_profile(user_id: str) -> dict:
logger = create_file_logger("user_service")
logger.info(
operation="fetchUserProfile",
message=f"Starting profile fetch for user {user_id}",
context={"user_id": user_id, "source": "user_service"}
)
try:
if user_id == "invalid":
raise ValueError("Invalid user ID format")
if user_id == "missing":
user_profile = None
else:
user_profile = {"id": user_id, "name": "John Doe", "email": "john@example.com"}
if user_profile is None:
logger.error(
operation="fetchUserProfile",
message="User profile not found in database",
context={"user_id": user_id, "query": "SELECT * FROM users WHERE id = ?"},
human_note="AI-TODO: Check if the user exists or if there's a database connection issue",
ai_todo="Analyze the database query and suggest fixes for null results"
)
return None
name = user_profile["name"]
logger.info(
operation="fetchUserProfile",
message=f"Successfully fetched profile for {name}",
context={"user_id": user_id, "profile_data": user_profile}
)
return user_profile
except Exception as e:
logger.log_exception(
operation="fetchUserProfile",
exception=e,
context={"user_id": user_id, "attempted_action": "profile_fetch"},
human_note="This error occurred during user profile fetching",
ai_todo="Suggest proper error handling and validation for user_id parameter"
)
return None
if __name__ == "__main__":
result1 = fetch_user_profile("user-123")
print("=== SUCCESS CASE ===")
result2 = fetch_user_profile("missing")
print("=== MISSING USER CASE ===")
result3 = fetch_user_profile("invalid")
print("=== ERROR CASE ===")
logger = create_file_logger("user_service")
print("\n=== ALL LOGS FOR AI ===")
print("Logs saved to:", logger.log_file)
print(logger.get_logs_for_ai())