Skip to content

Logging#147

Open
ParthShikhare19 wants to merge 2 commits into
ranahaani:masterfrom
ParthShikhare19:logging
Open

Logging#147
ParthShikhare19 wants to merge 2 commits into
ranahaani:masterfrom
ParthShikhare19:logging

Conversation

@ParthShikhare19
Copy link
Copy Markdown

🚀 Implement Structured Logging for GNews
for the issue #135
Description
Replace print statements with proper structured logging using Python's logging module to provide better debugging capabilities, configurable log levels, and optional file logging for production environments.

Why This Change?
Better Debugging: Structured logging provides more context than print statements
Configurable Levels: Support for DEBUG, INFO, WARNING, ERROR, CRITICAL levels
Production Ready: Optional file logging and proper log formatting
Maintainability: Easier to control log output in different environments
Implementation Details
Features Added:

Configurable Logging: Added log_level and log_file parameters to GNews constructor
Enhanced Format: Improved log format with timestamp, logger name, level, and message
File Logging: Optional file output in addition to console logging
Proper Log Levels: Replaced print statements with appropriate logger calls (WARNING/ERROR)
Backward Compatibility:

All new parameters are optional with sensible defaults
Existing code continues to work without modification
No breaking changes to the public API

Files Modified
gnews/gnews.py: Added logging configuration and replaced print statements
tests/test_gnews.py: Added logging suppression for clean test output
README.md: Documented new logging parameters and usage examples
Testing
All existing tests pass
Logging output is suppressed during testing
Verified functionality with different log levels and file output
Usage Examples

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.

2 participants