3.8 KiB
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
loggingandRotatingFileHandlerimports - Added module-level logger:
logger = logging.getLogger(__name__) - Replaced all
console.print()statements with appropriate logger calls:logger.debug()for verbose debugging infologger.info()for normal operationslogger.warning()for warningslogger.error()for errorslogger.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 cancellationslogger.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()withlogger.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()withlogger.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
- Production Monitoring: Full visibility into application behavior
- Troubleshooting: Detailed logs with timestamps and context
- Performance Tracking: Log rotation prevents disk space issues
- Debugging: Both file and console output for development
- 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:
- Run the CLI:
python -m youtube_cli "test query" - Run the TUI:
python youtube_tui/app.py - Run the API:
python app.py - Check logs:
cat ~/.config/youtube_cli/logs/app.log
Notes
- The
RotatingFileHandlerensures 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()