Skip to content

Enhancement: Replace print() statements with structured logging #16

@arunsanna

Description

@arunsanna

Description

The codebase contains 60+ print() statements used for debugging output. These should be replaced with Python's logging module for better control, filtering, and production readiness.

Locations

generator.py

  • Lines 17, 53, 77: Print statements in __init__
  • Lines 98-145: Conditional debug output throughout execution
  • Lines 295-341: CRASH_DEBUG comments with print statements

api.py

  • Multiple print statements for request logging

Current Code Example

# generator.py lines 98-145
print(f"DEBUG: model_id={model_id}")
print(f"DEBUG: extraction_result={extraction_result}")
# ... many more

Proposed Solution

1. Configure logging at module level

# generator.py
import logging

logger = logging.getLogger(__name__)

# In functions:
logger.debug("model_id=%s", model_id)
logger.info("AIBOM generation completed for %s", model_id)
logger.error("Failed to extract metadata: %s", error)

2. Use lazy string formatting

# Bad (string always constructed):
print(f"DEBUG: value={expensive_computation()}")

# Good (only constructed if DEBUG enabled):
logger.debug("value=%s", expensive_computation)

3. Add log levels appropriately

Level Use Case
DEBUG Detailed extraction steps, field values
INFO AIBOM generation success, API requests
WARNING Missing optional fields, fallback used
ERROR Extraction failures, API errors

Benefits

  • Controllable verbosity via log levels
  • Log rotation and persistence
  • Structured output for log aggregation
  • Quieter unit test output
  • Production-ready logging

Additional Cleanup

Remove CRASH_DEBUG comments and conditional print blocks (lines 295-341) that indicate iterative debugging rather than clean code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions