Padmanav commited on
Commit
d939b2e
·
1 Parent(s): a818a47

refactor: replace print() with structured logging across all agents and tools

Browse files
app/agents/bug_detection_agent.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  import json
2
  from app.tools.static_analyzer import run_full_analysis
3
  from app.tools.pytest_runner import run_tests
@@ -11,7 +14,7 @@ async def run(local_path: str) -> IssueReport:
11
  """
12
  Detect bugs, warnings and suggestions in a repository.
13
  """
14
- print("Running Bug Detection Agent...")
15
 
16
  # Step 1 - Run static analysis
17
  static_results = run_full_analysis(local_path)
@@ -82,5 +85,5 @@ Code Samples:
82
  )
83
  report.calculate_totals()
84
 
85
- print(f"Bug detection complete: {report.total_critical} critical, {report.total_warnings} warnings")
86
  return report
 
1
+ from app.core.logger import get_logger
2
+ logger = get_logger(__name__)
3
+
4
  import json
5
  from app.tools.static_analyzer import run_full_analysis
6
  from app.tools.pytest_runner import run_tests
 
14
  """
15
  Detect bugs, warnings and suggestions in a repository.
16
  """
17
+ logger.info("Starting bug detection agent", extra={"path": local_path})
18
 
19
  # Step 1 - Run static analysis
20
  static_results = run_full_analysis(local_path)
 
85
  )
86
  report.calculate_totals()
87
 
88
+ logger.info("Bug detection complete", extra={"critical": report.total_critical, "warnings": report.total_warnings})
89
  return report
app/agents/code_review_agent.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  import json
2
  from app.tools.file_scanner import get_python_files
3
  from app.core.llm import call_llm
@@ -10,7 +13,7 @@ async def run(local_path: str, metadata: RepositoryMetadata) -> ReviewSuggestion
10
  """
11
  Perform AI-powered code review on repository.
12
  """
13
- print("Running Code Review Agent...")
14
 
15
  # Step 1 - Get Python files
16
  python_files = get_python_files(local_path)
@@ -51,6 +54,5 @@ async def run(local_path: str, metadata: RepositoryMetadata) -> ReviewSuggestion
51
  overall_score=float(llm_data.get("overall_score", 5.0)),
52
  summary=llm_data.get("summary", "")
53
  )
54
-
55
- print(f"Code review complete: score {review.overall_score}/10")
56
  return review
 
1
+ from app.core.logger import get_logger
2
+ logger = get_logger(__name__)
3
+
4
  import json
5
  from app.tools.file_scanner import get_python_files
6
  from app.core.llm import call_llm
 
13
  """
14
  Perform AI-powered code review on repository.
15
  """
16
+ logger.info("Starting Code Review Agent", extra={"path": local_path})
17
 
18
  # Step 1 - Get Python files
19
  python_files = get_python_files(local_path)
 
54
  overall_score=float(llm_data.get("overall_score", 5.0)),
55
  summary=llm_data.get("summary", "")
56
  )
57
+ logger.info("Code review complete", extra={"score": review.overall_score})
 
58
  return review
app/agents/repo_analysis_agent.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  import json
2
  from app.tools.file_scanner import scan_repository, get_entry_points
3
  from app.tools.ast_parser import parse_repository
@@ -10,7 +13,7 @@ async def run(repo_url: str, local_path: str) -> RepositoryMetadata:
10
  """
11
  Analyze a repository and return structured metadata.
12
  """
13
- print("Running Repository Analysis Agent...")
14
 
15
  # Step 1 - Scan files
16
  scan_results = scan_repository(local_path)
@@ -56,5 +59,5 @@ Functions Found: {sum(len(r['functions']) for r in ast_results)}
56
  summary=llm_data.get("summary", "")
57
  )
58
 
59
- print(f"Analysis complete: {metadata.language}, {len(metadata.frameworks)} frameworks")
60
  return metadata
 
1
+ from app.core.logger import get_logger
2
+ logger = get_logger(__name__)
3
+
4
  import json
5
  from app.tools.file_scanner import scan_repository, get_entry_points
6
  from app.tools.ast_parser import parse_repository
 
13
  """
14
  Analyze a repository and return structured metadata.
15
  """
16
+ logger.info("Starting repository analysis agent", extra={"repo_url": repo_url})
17
 
18
  # Step 1 - Scan files
19
  scan_results = scan_repository(local_path)
 
59
  summary=llm_data.get("summary", "")
60
  )
61
 
62
+ logger.info("Repository analysis complete", extra={"language": metadata.language, "frameworks": len(metadata.frameworks)})
63
  return metadata
app/agents/report_generator_agent.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  from datetime import datetime
2
  from app.core.llm import call_llm
3
  from app.core.prompts import REPORT_GENERATOR_PROMPT
@@ -16,7 +19,7 @@ async def run(
16
  """
17
  Generate final engineering report combining all agent outputs.
18
  """
19
- print("Running Report Generator Agent...")
20
 
21
  # Step 1 - Build context for LLM
22
  analysis_summary = f"""
@@ -68,5 +71,5 @@ Summary: {review.summary}
68
  generated_at=datetime.now().strftime("%Y-%m-%d %H:%M:%S")
69
  )
70
 
71
- print("Report generation complete.")
72
  return report
 
1
+ from app.core.logger import get_logger
2
+ logger = get_logger(__name__)
3
+
4
  from datetime import datetime
5
  from app.core.llm import call_llm
6
  from app.core.prompts import REPORT_GENERATOR_PROMPT
 
19
  """
20
  Generate final engineering report combining all agent outputs.
21
  """
22
+ logger.info("Starting report generator agent")
23
 
24
  # Step 1 - Build context for LLM
25
  analysis_summary = f"""
 
71
  generated_at=datetime.now().strftime("%Y-%m-%d %H:%M:%S")
72
  )
73
 
74
+ logger.info("Report generation complete", extra={"generated_at": report.generated_at})
75
  return report
app/agents/test_generation_agent.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  from app.tools.file_scanner import get_python_files
2
  from app.tools.ast_parser import parse_python_file
3
  from app.core.llm import call_llm
@@ -24,7 +27,7 @@ async def run(local_path: str) -> GeneratedTests:
24
  """
25
  Generate pytest test cases for uncovered functions.
26
  """
27
- print("Running Test Generation Agent...")
28
 
29
  # Step 1 - Get Python files
30
  python_files = get_python_files(local_path)
@@ -76,5 +79,5 @@ async def run(local_path: str) -> GeneratedTests:
76
  total_tests_generated=test_count
77
  )
78
 
79
- print(f"Test generation complete: {test_count} tests generated")
80
  return result
 
1
+ from app.core.logger import get_logger
2
+ logger = get_logger(__name__)
3
+
4
  from app.tools.file_scanner import get_python_files
5
  from app.tools.ast_parser import parse_python_file
6
  from app.core.llm import call_llm
 
27
  """
28
  Generate pytest test cases for uncovered functions.
29
  """
30
+ logger.info("Starting test generation agent", extra={"path": local_path})
31
 
32
  # Step 1 - Get Python files
33
  python_files = get_python_files(local_path)
 
79
  total_tests_generated=test_count
80
  )
81
 
82
+ logger.info("Test generation complete", extra={"tests_generated": test_count})
83
  return result
app/core/logger.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ import sys
3
+
4
+ def get_logger(name: str) -> logging.Logger:
5
+ logger = logging.getLogger(name)
6
+ if not logger.handlers:
7
+ handler = logging.StreamHandler(sys.stdout)
8
+ formatter = logging.Formatter(
9
+ fmt="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
10
+ datefmt="%Y-%m-%dT%H:%M:%S",
11
+ )
12
+ handler.setFormatter(formatter)
13
+ logger.addHandler(handler)
14
+ logger.setLevel(logging.INFO)
15
+ return logger
app/tools/github_tool.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  import os
2
  import shutil
3
  from pathlib import Path
@@ -22,9 +25,9 @@ def clone_repository(github_url: str) -> str:
22
  # Create parent directory
23
  clone_dir.mkdir(parents=True, exist_ok=True)
24
 
25
- print(f"Cloning {github_url} into {local_path}...")
26
  Repo.clone_from(github_url, str(local_path))
27
- print("Clone complete.") # nosec B608
28
 
29
  return str(local_path)
30
 
@@ -33,4 +36,4 @@ def delete_repository(local_path: str):
33
  path = Path(local_path)
34
  if path.exists():
35
  shutil.rmtree(path, ignore_errors=True)
36
- print(f"Deleted repository at {local_path}")
 
1
+ from app.core.logger import get_logger
2
+ logger = get_logger(__name__)
3
+
4
  import os
5
  import shutil
6
  from pathlib import Path
 
25
  # Create parent directory
26
  clone_dir.mkdir(parents=True, exist_ok=True)
27
 
28
+ logger.info("Cloning repository", extra={"url": github_url, "destination": str(local_path)})
29
  Repo.clone_from(github_url, str(local_path))
30
+ logger.info("Clone complete", extra={"path": str(local_path)}) # nosec B608
31
 
32
  return str(local_path)
33
 
 
36
  path = Path(local_path)
37
  if path.exists():
38
  shutil.rmtree(path, ignore_errors=True)
39
+ logger.info("Deleted cloned repository", extra={"path": str(local_path)})