youtube-cli/LOGGING_SUMMARY.md
2026-02-28 02:02:45 -06:00

3.8 KiB

Logging Implementation Summary

Overview

Comprehensive logging has been added to all Python files in the YouTube CLI project.

Changes Made

1. Logs Directory

  • Created /Users/user/Projects/youtube-cli/logs/ directory
  • Added logs/ to .gitignore (already present)

2. Logging Configuration

All Python files now have:

  • Log file: ~/.config/youtube_cli/logs/app.log
  • Rotation: 10MB max, keep 5 backups
  • Level: DEBUG (file), INFO (console)
  • Format: %(asctime)s | %(name)s | %(levelname)s | %(message)s

3. Files Modified

/Users/user/Projects/youtube-cli/youtube_cli/main.py

  • Added logging and RotatingFileHandler imports
  • Added module-level logger: logger = logging.getLogger(__name__)
  • Replaced all console.print() statements with appropriate logger calls:
    • logger.debug() for verbose debugging info
    • logger.info() for normal operations
    • logger.warning() for warnings
    • logger.error() for errors
    • logger.exception() for exceptions (includes traceback)

Key logging additions:

  • Search operations
  • Download operations
  • Archive operations
  • Configuration loading
  • Network share operations
  • Error handling with full context

/Users/user/Projects/youtube-cli/youtube_tui/app.py

  • Added logging imports and configuration
  • Added module-level logger
  • Added logging initialization in main() function

/Users/user/Projects/youtube-cli/youtube_tui/services/download_manager.py

  • Added logging imports and configuration
  • Added module-level logger
  • Replaced console.print() with:
    • logger.warning() for cancellations
    • logger.error() for errors

/Users/user/Projects/youtube-cli/youtube_tui/services/youtube.py

  • Added logging imports and configuration
  • Added module-level logger
  • Replaced self.console.print() with logger.error() for service errors

/Users/user/Projects/youtube-cli/youtube_tui/services/queue.py

  • Added logging imports and configuration
  • Added module-level logger
  • Replaced console.print() with logger.warning() for queue operations

/Users/user/Projects/youtube-cli/app.py (REST API)

  • Added logging imports and configuration
  • Added module-level logger
  • Added logging initialization in module scope

4. Logging Levels Used

Level Usage Example
DEBUG Detailed debugging info Download directory paths
INFO Normal operations Search queries, download starts, completions
WARNING Non-critical issues Invalid inputs, skipped operations
ERROR Errors Failed downloads, missing dependencies
CRITICAL Critical failures Not used (reserved for severe issues)

5. Benefits

  1. Production Monitoring: Full visibility into application behavior
  2. Troubleshooting: Detailed logs with timestamps and context
  3. Performance Tracking: Log rotation prevents disk space issues
  4. Debugging: Both file and console output for development
  5. Consistency: Same logging approach across all modules

Usage

View Logs in Real-Time

tail -f ~/.config/youtube_cli/logs/app.log

Search Logs

grep "ERROR" ~/.config/youtube_cli/logs/app.log
grep "WARNING" ~/.config/youtube_cli/logs/app.log

Log File Location

  • Logs are stored in: ~/.config/youtube_cli/logs/app.log
  • Old logs are automatically rotated and archived

Testing

To verify logging works:

  1. Run the CLI: python -m youtube_cli "test query"
  2. Run the TUI: python youtube_tui/app.py
  3. Run the API: python app.py
  4. Check logs: cat ~/.config/youtube_cli/logs/app.log

Notes

  • The RotatingFileHandler ensures log files don't grow indefinitely
  • Console output is limited to INFO level for cleaner terminal output
  • File output captures all DEBUG level messages for thorough logging
  • All exceptions are logged with full tracebacks using logger.error()