Skip to content

Commit 6bf87d0

Browse files
committed
refactor: ♻️ changing outdated prints to logger
1 parent 61586cd commit 6bf87d0

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

app/services/file_manipulator.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import os
22
from app.services.filler import Filler
33
from app.services.llm import LLM
4+
from app.core.logging import get_logger
5+
6+
logger = get_logger(__name__)
47

58

69
class FileManipulator:
@@ -39,25 +42,23 @@ def fill_form(self, user_input: str, fields: list, pdf_form_path: str, model: st
3942
It receives the raw data, runs the PDF filling logic,
4043
and returns the path to the newly created file.
4144
"""
42-
print("[1] Received request from frontend.")
43-
print(f"[2] PDF template path: {pdf_form_path}")
45+
logger.info("[1] Received request from frontend.")
46+
logger.info("[2] PDF template path: %s", pdf_form_path)
4447

4548
if not os.path.exists(pdf_form_path):
4649
raise FileNotFoundError(f"PDF template not found at {pdf_form_path}")
4750

48-
print("[3] Starting extraction and PDF filling process...")
51+
logger.info("[3] Starting extraction and PDF filling process...")
4952
try:
5053
self.llm._target_fields = fields
5154
self.llm._transcript_text = user_input
5255
self.llm._model = model
5356
output_name = self.filler.fill_form(pdf_form=pdf_form_path, llm=self.llm)
5457

55-
print("\n----------------------------------")
56-
print("✅ Process Complete.")
57-
print(f"Output saved to: {output_name}")
58+
logger.info("Process complete. Output saved to: %s", output_name)
5859

5960
return output_name
6061

6162
except Exception as e:
62-
print(f"An error occurred during PDF generation: {e}")
63+
logger.error("An error occurred during PDF generation: %s", e)
6364
raise e

app/services/llm.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
from requests.exceptions import Timeout, RequestException
55

66
from app.core.config import OLLAMA_HOST, OLLAMA_MODEL
7+
from app.core.logging import get_logger
8+
9+
logger = get_logger(__name__)
710

811

912
class LLM:
@@ -51,9 +54,9 @@ def main_loop(self):
5154
json_data = response.json()
5255
break
5356
except Timeout:
54-
print(f"[LOG]: Ollama request timed out (attempt {attempt+1}) for field '{field}'. Retrying...")
57+
logger.warning("Ollama request timed out (attempt %d) for field '%s'. Retrying...", attempt + 1, field)
5558
except RequestException as e:
56-
print(f"[LOG]: Ollama request failed: {e}")
59+
logger.error("Ollama request failed: %s", e)
5760
except requests.exceptions.ConnectionError:
5861
raise ConnectionError(
5962
f"Could not connect to Ollama at {ollama_url}. "
@@ -67,12 +70,9 @@ def main_loop(self):
6770
else:
6871
parsed_response = json_data["response"]
6972
self.add_response_to_json(field, parsed_response)
70-
print(f"[{i}/{total_fields}] Extracted data for field '{field}' successfully.")
73+
logger.info("[%d/%d] Extracted data for field '%s' successfully.", i, total_fields, field)
7174

72-
print("----------------------------------")
73-
print("\t[LOG] Resulting JSON created from the input text:")
74-
print(json.dumps(self._json, indent=2))
75-
print("--------- extracted data ---------")
75+
logger.info("Resulting JSON created from the input text:\n%s", json.dumps(self._json, indent=2))
7676

7777
return self
7878

0 commit comments

Comments
 (0)