Skip to content

[FEAT]: Add structured logging across the project and replace print() diagnostics#365

Open
SHANKAR8983 wants to merge 2 commits intofireform-core:mainfrom
SHANKAR8983:feat/structured-logging
Open

[FEAT]: Add structured logging across the project and replace print() diagnostics#365
SHANKAR8983 wants to merge 2 commits intofireform-core:mainfrom
SHANKAR8983:feat/structured-logging

Conversation

@SHANKAR8983
Copy link
Copy Markdown

Description

The project currently uses print() statements throughout the codebase for diagnostics and debugging.

While useful during development, print() has several limitations in production environments:

  • No timestamps
  • No severity levels (INFO, WARNING, ERROR)
  • No module/source identification
  • Cannot easily redirect logs to files or external monitoring systems

This PR introduces structured logging to improve observability, debugging, and production readiness of the project.

Rationale

A centralized logging system provides several benefits:

  • Timestamped logs for better debugging
  • Severity levels (INFO, DEBUG, ERROR, WARNING)
  • Consistent logging format across modules
  • Ability to route logs to files or monitoring tools
  • Cleaner debugging and production diagnostics

Changes Made

1. Created src/logger.py — Centralized logging utility

import logging

def setup_logger(name: str):
    logger = logging.getLogger(name)

    if logger.handlers:
        return logger

    logger.setLevel(logging.INFO)

    handler = logging.StreamHandler()
    formatter = logging.Formatter(
        "%(asctime)s | %(levelname)s | %(name)s | %(message)s",
        datefmt="%Y-%m-%d %H:%M:%S"
    )
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    return logger

2. Updated src/llm.py

Before:

print("\t[LOG] Resulting JSON created from the input text:")
print(json.dumps(self._json, indent=2))
print(f"\t[LOG]: Formating plural values for JSON, [For input {plural_value}]...")

After:

logger.info("Resulting JSON created from the input text:")
logger.info(json.dumps(self._json, indent=2))
logger.info(f"Formatting plural values for JSON, input: {plural_value}")

3. Updated src/file_manipulator.py

Before:

print("[1] Received request from frontend.")
print(f"[2] PDF template path: {pdf_form_path}")
print(f"Error: PDF template not found at {pdf_form_path}")

After:

logger.info("Received request from frontend.")
logger.info(f"PDF template path: {pdf_form_path}")
logger.error(f"PDF template not found at {pdf_form_path}")

Sample Log Output

2026-03-28 08:30:01 | INFO | src.llm | Resulting JSON created from the input text:
2026-03-28 08:30:01 | INFO | src.llm | Formatting plural values for JSON, input: ...
2026-03-28 08:30:01 | INFO | src.file_manipulator | Process Complete.
2026-03-28 08:30:01 | ERROR | src.file_manipulator | PDF template not found at ...

Closes #220

@SHANKAR8983
Copy link
Copy Markdown
Author

Hey @marcvargas, this PR adds structured logging across the project, replacing print() diagnostics. Would appreciate a review 🙏

@SHANKAR8983 SHANKAR8983 force-pushed the feat/structured-logging branch from 1ef7d68 to e3c0e0a Compare April 26, 2026 19:24
@SHANKAR8983
Copy link
Copy Markdown
Author

Hey @marcvargas, just wanted to let you know I've resolved the merge conflicts and the branch is now clean. Would love your feedback whenever you get a chance! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Add structured logging across the project and replace print() diagnostics

1 participant