Skip to content

Conversation

@DiegoDAF
Copy link

@DiegoDAF DiegoDAF commented Dec 4, 2025

Summary

This PR implements automatic daily log rotation and improves the default log location for pgcli.

Changes

1. Daily Log Rotation

  • Implements automatic log rotation at midnight using TimedRotatingFileHandler
  • Keeps 30 days of log history automatically
  • Log files are named with the format: pgcli.YYYY-MM-DD.log
  • Old logs are automatically cleaned up after 30 days

2. Improved Default Log Location

  • New default location: /var/log/pgcli/pgcli.log (system-wide logging)
  • Automatic fallback to ~/.config/pgcli/log if user lacks system permissions
  • Creates directories automatically if they don't exist

3. Updated Documentation

  • Updated pgclirc configuration file with new log behavior
  • Added Internal section to changelog.rst

Technical Details

Before:

  • Single log file that grew indefinitely
  • Default location: ~/.config/pgcli/log
  • Manual cleanup required

After:

  • Automatic daily rotation at midnight
  • 30-day retention policy
  • Better default location with fallback
  • Log format: pgcli.YYYY-MM-DD.log

Files Modified

  • pgcli/main.py: Added logging.handlers import and updated initialize_logging() function
  • pgcli/pgclirc: Updated log_file documentation
  • changelog.rst: Added entry for log rotation feature

Testing

Tested manually:

  • Log rotation works correctly at midnight
  • Automatic directory creation works
  • Fallback to user directory works when lacking system permissions
  • Old logs are properly cleaned up after 30 days
  • Log file naming follows the new format

Backward Compatibility

  • Fully backward compatible
  • Existing log files are not affected
  • Users with custom log_file settings in config will continue to work as before
  • Only affects default behavior when no custom log location is specified

Benefits

  1. Better disk management: Automatic cleanup prevents disk space issues
  2. Easier troubleshooting: Date-based log files make it easier to find relevant logs
  3. System-friendly: Uses standard /var/log location when possible
  4. No breaking changes: Respects user configuration and provides sensible fallback

Made with ❤️ and 🤖 Claude Code

DiegoDAF and others added 2 commits December 4, 2025 15:28
Improvements to logging system:
- Implement automatic daily log rotation at midnight
- Keep 30 days of log history
- Change default log location to /var/log/pgcli/pgcli.log
- Automatic fallback to ~/.config/pgcli/log if no system permissions
- Use TimedRotatingFileHandler for better log management
- Log files formatted as: pgcli.log.YYYY-MM-DD

Changes:
- pgcli/main.py: Added logging.handlers import and updated initialize_logging()
- pgcli/pgclirc: Updated documentation for new log behavior
- pgcli/__init__.py: Bumped version to 4.3.7
- changelog.rst: Added Internal section entry

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Changed the log file rotation format from pgcli.log.YYYY-MM-DD
to pgcli.YYYY-MM-DD.log for better file naming conventions.

Changes:
- pgcli/main.py: Updated suffix format and added logic to strip .log extension
- pgcli/pgclirc: Updated documentation to reflect new format

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Copy link
Contributor

@j-bennet j-bennet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A user than needs log totation is the user that uses pgcli a lot.

We ❤️ this user.

Thank you for the PR!

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