logger file (#6)
Browse files- git ignore updated (5b4018c0589d83cfb489ef09e7e1e5c7848ff8ca)
- logger file introduced (40ae10a1899d78ccfcebd7d4fa2f78fb3fc64cc1)
- .gitignore +5 -1
- agentic_implementation/agent.py +2 -2
- agentic_implementation/email_scraper.py +24 -24
- agentic_implementation/logger.py +22 -18
.gitignore
CHANGED
@@ -5,4 +5,8 @@ venv/
|
|
5 |
__pycache__/
|
6 |
*.py[cod]
|
7 |
*.pyo
|
8 |
-
*.pyd
|
|
|
|
|
|
|
|
|
|
5 |
__pycache__/
|
6 |
*.py[cod]
|
7 |
*.pyo
|
8 |
+
*.pyd
|
9 |
+
*.log
|
10 |
+
|
11 |
+
agentic_implementation/*.json
|
12 |
+
agentic_implementation/*.db
|
agentic_implementation/agent.py
CHANGED
@@ -42,7 +42,7 @@ def run_agent():
|
|
42 |
continue
|
43 |
|
44 |
# print plan for user transparency
|
45 |
-
print("\n\
|
46 |
print(plan)
|
47 |
print("\n\n")
|
48 |
|
@@ -102,7 +102,7 @@ def run_agent():
|
|
102 |
output = act(updated_step)
|
103 |
results[updated_step.action] = output
|
104 |
logger.info("Action '%s' executed successfully.", updated_step.action)
|
105 |
-
print(f"π§ Ran `{updated_step.action}`
|
106 |
except Exception as e:
|
107 |
logger.error("Error executing action '%s': %s", updated_step.action, e)
|
108 |
print(f"β Error running `{updated_step.action}`: {e}")
|
|
|
42 |
continue
|
43 |
|
44 |
# print plan for user transparency
|
45 |
+
print("\n\nplan:")
|
46 |
print(plan)
|
47 |
print("\n\n")
|
48 |
|
|
|
102 |
output = act(updated_step)
|
103 |
results[updated_step.action] = output
|
104 |
logger.info("Action '%s' executed successfully.", updated_step.action)
|
105 |
+
print(f"π§ Ran `{updated_step.action}`")
|
106 |
except Exception as e:
|
107 |
logger.error("Error executing action '%s': %s", updated_step.action, e)
|
108 |
print(f"β Error running `{updated_step.action}`: {e}")
|
agentic_implementation/email_scraper.py
CHANGED
@@ -27,32 +27,32 @@ def validate_email_setup():
|
|
27 |
print("=== Email Setup Validation ===")
|
28 |
|
29 |
# Check .env file existence
|
30 |
-
env_file_exists = os.path.exists('.env')
|
31 |
-
print(f".env file exists: {'β
Yes' if env_file_exists else 'β No'}")
|
32 |
|
33 |
-
if not env_file_exists:
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
|
40 |
# Check environment variables
|
41 |
issues = []
|
42 |
|
43 |
-
if not EMAIL_ID:
|
44 |
-
|
45 |
-
elif '@' not in EMAIL_ID:
|
46 |
-
|
47 |
-
elif not EMAIL_ID.endswith('@gmail.com'):
|
48 |
-
|
49 |
-
|
50 |
-
if not APP_PASSWORD:
|
51 |
-
|
52 |
-
elif len(APP_PASSWORD) != 16:
|
53 |
-
|
54 |
-
elif ' ' in APP_PASSWORD:
|
55 |
-
|
56 |
|
57 |
if not os.getenv("OPENAI_API_KEY"):
|
58 |
issues.append("OPENAI_API_KEY not set (needed for query processing)")
|
@@ -76,9 +76,9 @@ def _imap_connect():
|
|
76 |
|
77 |
if EMAIL_ID:
|
78 |
print(f"Email ID: {EMAIL_ID[:5]}...@{EMAIL_ID.split('@')[1] if '@' in EMAIL_ID else 'INVALID'}")
|
79 |
-
if APP_PASSWORD:
|
80 |
-
|
81 |
-
|
82 |
|
83 |
if not EMAIL_ID or not APP_PASSWORD:
|
84 |
error_msg = "Missing credentials in environment variables!"
|
|
|
27 |
print("=== Email Setup Validation ===")
|
28 |
|
29 |
# Check .env file existence
|
30 |
+
# env_file_exists = os.path.exists('.env')
|
31 |
+
# print(f".env file exists: {'β
Yes' if env_file_exists else 'β No'}")
|
32 |
|
33 |
+
# if not env_file_exists:
|
34 |
+
# print("β No .env file found! Create one with:")
|
35 |
+
# print(" [email protected]")
|
36 |
+
# print(" APP_PASSWORD=your_16_char_app_password")
|
37 |
+
# print(" OPENAI_API_KEY=your_openai_key")
|
38 |
+
# return False
|
39 |
|
40 |
# Check environment variables
|
41 |
issues = []
|
42 |
|
43 |
+
# if not EMAIL_ID:
|
44 |
+
# issues.append("EMAIL_ID not set or empty")
|
45 |
+
# elif '@' not in EMAIL_ID:
|
46 |
+
# issues.append("EMAIL_ID doesn't look like an email address")
|
47 |
+
# elif not EMAIL_ID.endswith('@gmail.com'):
|
48 |
+
# issues.append("EMAIL_ID should be a Gmail address (@gmail.com)")
|
49 |
+
|
50 |
+
# if not APP_PASSWORD:
|
51 |
+
# issues.append("APP_PASSWORD not set or empty")
|
52 |
+
# elif len(APP_PASSWORD) != 16:
|
53 |
+
# issues.append(f"APP_PASSWORD should be 16 characters, got {len(APP_PASSWORD)}")
|
54 |
+
# elif ' ' in APP_PASSWORD:
|
55 |
+
# issues.append("APP_PASSWORD should not contain spaces (remove spaces from app password)")
|
56 |
|
57 |
if not os.getenv("OPENAI_API_KEY"):
|
58 |
issues.append("OPENAI_API_KEY not set (needed for query processing)")
|
|
|
76 |
|
77 |
if EMAIL_ID:
|
78 |
print(f"Email ID: {EMAIL_ID[:5]}...@{EMAIL_ID.split('@')[1] if '@' in EMAIL_ID else 'INVALID'}")
|
79 |
+
# if APP_PASSWORD:
|
80 |
+
# print(f"App Password length: {len(APP_PASSWORD)} characters")
|
81 |
+
# print(f"App Password format: {'β
Looks correct (16 chars)' if len(APP_PASSWORD) == 16 else f'β Expected 16 chars, got {len(APP_PASSWORD)}'}")
|
82 |
|
83 |
if not EMAIL_ID or not APP_PASSWORD:
|
84 |
error_msg = "Missing credentials in environment variables!"
|
agentic_implementation/logger.py
CHANGED
@@ -1,25 +1,29 @@
|
|
1 |
import logging
|
2 |
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
def
|
5 |
-
"""
|
6 |
-
|
7 |
-
|
8 |
-
"""
|
9 |
-
logger = logging.getLogger(name)
|
10 |
-
logger.setLevel(level)
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
'%(asctime)s %(levelname)s %(name)s - %(message)s'
|
18 |
-
)
|
19 |
-
handler.setFormatter(formatter)
|
20 |
-
logger.addHandler(handler)
|
21 |
|
22 |
-
|
|
|
|
|
|
|
23 |
|
24 |
# Module-level default logger
|
25 |
-
logger =
|
|
|
1 |
import logging
|
2 |
import sys
|
3 |
+
from datetime import datetime
|
4 |
+
from loguru import logger as _logger
|
5 |
+
from pathlib import Path
|
6 |
+
import sys
|
7 |
+
|
8 |
+
_print_level = "INFO"
|
9 |
+
|
10 |
+
PROJECT_ROOT = Path(sys.path[0]) # Assuming the script is run from the project root
|
11 |
|
12 |
+
def define_log_level(print_level="INFO", logfile_level="DEBUG", name: str = None):
|
13 |
+
"""Adjust the log level to above level"""
|
14 |
+
global _print_level
|
15 |
+
_print_level = print_level
|
|
|
|
|
|
|
16 |
|
17 |
+
current_date = datetime.now()
|
18 |
+
formatted_date = current_date.strftime("%Y%m%d%H%M%S")
|
19 |
+
log_name = (
|
20 |
+
f"{name}_{formatted_date}" if name else formatted_date
|
21 |
+
) # name a log with prefix name
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
_logger.remove()
|
24 |
+
_logger.add(sys.stderr, level=print_level)
|
25 |
+
_logger.add(PROJECT_ROOT / f"logs/{log_name}.log", level=logfile_level)
|
26 |
+
return _logger
|
27 |
|
28 |
# Module-level default logger
|
29 |
+
logger = define_log_level()
|