Add log rotation support with multiple modes#1547
Draft
DiegoDAF wants to merge 1 commit intodbcli:mainfrom
Draft
Add log rotation support with multiple modes#1547DiegoDAF wants to merge 1 commit intodbcli:mainfrom
DiegoDAF wants to merge 1 commit intodbcli:mainfrom
Conversation
Implements a flexible log rotation system inspired by PostgreSQL's log_filename parameter and pgadmin4's rotation mechanism. Features: - Four rotation modes: none (default), day-of-week, day-of-month, date - Customizable log destination directory - Backward compatible with existing configurations - Uses system locale for day names (strftime %a) - No automatic deletion of old log files Configuration: - log_rotation_mode: Controls how logs are rotated * none: Single pgcli.log file (default, backward compatible) * day-of-week: pgcli-Mon.log through pgcli-Sun.log (overwrites weekly) * day-of-month: pgcli-01.log through pgcli-31.log (overwrites monthly) * date: pgcli-YYYYMMDD.log (never overwrites) - log_destination: Specifies directory for log files (default: ~/.config/pgcli/log) Tests: - Added 5 pytest unit tests for all rotation modes - Added behave integration tests with 4 scenarios - All tests verify correct file naming and backward compatibility Files modified: - pgcli/main.py: Updated initialize_logging() with rotation logic - pgcli/__init__.py: Bumped version to 4.3.9 - pgcli/pgclirc: Added new config parameters with documentation - tests/test_main.py: Added unit tests - tests/features/log_rotation.feature: Added integration tests - tests/features/steps/log_rotation.py: Added test steps - changelog.rst: Documented new feature in Upcoming section - AUTHORS: Added Diego to contributors - .gitignore: Excluded pgcli/__init__.py from tracking - pyproject.toml: Fixed paramiko version constraint for sshtunnel compatibility 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds flexible log rotation support to pgcli, inspired by PostgreSQL's
log_filenameconfiguration and pgadmin4's implementation.Features
New Configuration Options
log_rotation_mode- Controls how log files are rotated:none(default) - Single log filepgcli.log(backward compatible)day-of-week- Rotates by day name (Mon-Sun), overwrites weeklyday-of-month- Rotates by day number (01-31), overwrites monthlydate- Rotates by date (YYYYMMDD), never overwriteslog_destination- Specifies log directory:default- Uses standard config location (~/.config/pgcli/log)Characteristics
strftime("%a")Example Configuration
Generated Filenames
none:pgcli.logday-of-week:pgcli-Mon.log,pgcli-Tue.log, etc.day-of-month:pgcli-01.log,pgcli-02.log, ...,pgcli-31.logdate:pgcli-20250127.log,pgcli-20250128.log, etc.Testing
Complete test coverage included:
tests/test_main.pytests/features/log_rotation.featureRelated Issues
Closes #1541 - This is the corrected and complete implementation with proper tests.