Skip to content

Replace DEBUG_MODE print() statements with proper logging #10

@AdamEXu

Description

@AdamEXu

Problem

Found 20+ instances of debug print statements throughout the codebase:

if DEBUG_MODE:
    print(f"DEBUG: Some debug info")

Issues with print() for debugging

  1. No log levels - Can't filter by severity (INFO, WARNING, ERROR)
  2. No structured logging - Hard to parse/search logs
  3. Doesn't write to log files - Only goes to stdout
  4. No timestamps - Hard to correlate events
  5. No context - Missing module/function name
  6. Production risk - If DEBUG_MODE accidentally enabled, prints go to stdout

Affected Files

  • services/data_deletion.py - 4 instances
  • services/event_service.py - 6 instances
  • services/auth_service.py - 8+ instances
  • Many other files

Current State (Bad)

if DEBUG_MODE:
    print(f"DEBUG: Received code: {auth_code[:20]}...")
    print(f"DEBUG: Using WorkOS SSO for Google OAuth")

Desired State (Good)

logger.debug(f"Received code: {auth_code[:20]}...")
logger.debug("Using WorkOS SSO for Google OAuth")

Benefits of Proper Logging

✅ Log levels (DEBUG, INFO, WARNING, ERROR, CRITICAL)
✅ Automatic timestamps
✅ Module/function context
✅ Can write to files, syslog, external services
✅ Structured logging support
✅ Better performance (logging framework handles filtering)
✅ Industry standard

Recommended Implementation

1. Create logging config

# utils/logging_config.py
import logging
from config import DEBUG_MODE

def setup_logging():
    log_level = logging.DEBUG if DEBUG_MODE else logging.INFO
    
    logging.basicConfig(
        level=log_level,
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
        handlers=[
            logging.StreamHandler(),  # Console
            logging.FileHandler('app.log')  # File
        ]
    )

2. Use in each module

import logging
logger = logging.getLogger(__name__)

# Instead of:
if DEBUG_MODE:
    print(f"DEBUG: Something happened")

# Do this:
logger.debug("Something happened")
logger.info("User logged in: %s", user_email)
logger.warning("Rate limit approaching: %d/%d", current, limit)
logger.error("Failed to delete user: %s", error)

3. Structured logging (optional but recommended)

import structlog

logger = structlog.get_logger()
logger.info("user_login", user_email=email, ip=ip_address)

Migration Strategy

  1. Phase 1: Add logging config to app.py
  2. Phase 2: Replace prints in critical paths (auth, API, data deletion)
  3. Phase 3: Replace remaining prints
  4. Phase 4: Remove if DEBUG_MODE guards (logging framework handles this)

Quick Win

Replace all instances with a regex find/replace:

Find: if DEBUG_MODE:\s+print\(f?"DEBUG: (.+)"\)
Replace: logger.debug("\1")

Labels

technical-debt, logging, low-priority, good-first-issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions