Add log rotation support with multiple modes #1547
Draft
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.