Skip to content

Add log rotation support with multiple modes#1547

Draft
DiegoDAF wants to merge 1 commit intodbcli:mainfrom
DiegoDAF:feature/log-rotation-pr-upstream
Draft

Add log rotation support with multiple modes#1547
DiegoDAF wants to merge 1 commit intodbcli:mainfrom
DiegoDAF:feature/log-rotation-pr-upstream

Conversation

@DiegoDAF
Copy link
Copy Markdown

Summary

This PR adds flexible log rotation support to pgcli, inspired by PostgreSQL's log_filename configuration and pgadmin4's implementation.

Features

New Configuration Options

  1. log_rotation_mode - Controls how log files are rotated:

    • none (default) - Single log file pgcli.log (backward compatible)
    • day-of-week - Rotates by day name (Mon-Sun), overwrites weekly
    • day-of-month - Rotates by day number (01-31), overwrites monthly
    • date - Rotates by date (YYYYMMDD), never overwrites
  2. log_destination - Specifies log directory:

    • default - Uses standard config location (~/.config/pgcli/log)
    • Custom path - Any valid directory

Characteristics

  • Backward compatible: Works exactly as before without configuration
  • System locale aware: Uses system's day names via strftime("%a")
  • No automatic deletion: Old log files are never deleted automatically
  • Flexible: Allows custom log directory location

Example Configuration

[main]
log_rotation_mode = day-of-week
log_destination = default

Generated Filenames

  • none: pgcli.log
  • day-of-week: pgcli-Mon.log, pgcli-Tue.log, etc.
  • day-of-month: pgcli-01.log, pgcli-02.log, ..., pgcli-31.log
  • date: pgcli-20250127.log, pgcli-20250128.log, etc.

Testing

Complete test coverage included:

  • 5 pytest unit tests in tests/test_main.py
  • 4 behave integration tests in tests/features/log_rotation.feature

Related Issues

Closes #1541 - This is the corrected and complete implementation with proper tests.

Loading
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.

1 participant