Logging Cleanup
by Technology Pill Business Solution https://tecpill.com/ , Sayed Mohammed Aqeel Ebrahim https://tecpill.com/| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Lines of code | 317 |
| Technical Name |
logging_clean_up |
| License | LGPL-3 |
| Website | https://tecpill.com/ |
| Versions | 16.0 17.0 18.0 19.0 |
| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Lines of code | 317 |
| Technical Name |
logging_clean_up |
| License | LGPL-3 |
| Website | https://tecpill.com/ |
| Versions | 16.0 17.0 18.0 19.0 |
Logging Cleanup
Configurable log retention policies, cleanup rotation modes, and manual cleanup for ir.logging in Odoo 19.
What Makes This Module Special
- Configurable log retention policies per log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
- Two rotation modes: time-based and count-based cleanup strategies
- Automated scheduled cleanup via cron job for hands-free operation
- Optimized SQL-based cleanup for large log tables with minimal performance impact
Main configuration interface
Key Features
Configurable Retention Policies
- - Set retention days per log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
- - JSON-based configuration for flexible retention rules
- - Default retention: DEBUG (3 days), INFO (7 days), WARNING (30 days), ERROR (90 days), CRITICAL (180 days)
- - Easy configuration through Settings -> Technical -> Logging Cleanup
JSON retention rules configuration example
Rotation Modes
- - Time-Based Rotation: Deletes logs older than retention period per level
- - Count-Based Rotation: Keeps only the last N records globally (default: 100,000)
- - Switch between modes easily in settings
- - Enable/disable cleanup functionality as needed
Automated Cleanup
- - Scheduled cron job runs daily to clean up old logs
- - Configurable via Settings -> Technical -> Automation -> Scheduled Actions
- - Audit logging after each cleanup operation
- - No manual intervention required once configured
Automated cleanup scheduled action
Performance Optimized
- - Optimized SQL-based cleanup for large tables
- - Minimal database load during cleanup operations
- - Efficient deletion using RETURNING clause for accurate counts
- - Safe transaction handling with proper commits
Manual Cleanup
- - Manual cleanup button in Settings -> Technical -> Logging Cleanup
- - Manual cleanup action in Logs list view
- - Immediate feedback with notification showing deleted record count
- - Restricted to users with Technical Settings access
Why You Need This Module
The Problem
- Odoo's ir.logging table grows indefinitely without cleanup
- Large log tables can slow down database performance
- No built-in mechanism to automatically clean old logs
- Manual cleanup requires direct database access and SQL knowledge
- Different log levels may need different retention policies
The Solution
- Automated Cleanup: Scheduled daily cleanup via cron job
- Flexible Configuration: Set retention policies per log level
- Two Rotation Modes: Time-based or count-based strategies
- Easy Management: Configure everything through Odoo Settings UI
- Manual Control: Trigger cleanup on-demand when needed
- Performance Optimized: Efficient SQL-based deletion for large tables
- Audit Trail: Logs cleanup operations for tracking
Installation & Configuration
Requirements
- - Odoo 19.0+ required
- - Dependencies: base, base_setup (automatically included)
- - No additional modules required
- - Database superuser access for initial setup
Installation Steps:
- Place module in addons directory
- Update app list in Odoo
- Install "Logging Cleanup" module
- Go to Settings -> Technical -> Logging Cleanup
- Configure retention policies and enable cleanup
Configuration Guide
- Enable Cleanup: Check "Log Cleanup Enabled" to activate automated cleanup
- Rotation Mode: Choose "Time-Based" (per level retention) or "Count-Based" (keep last N records)
- Retention Rules: Configure JSON with retention days per log level
- Max Records: Set maximum records to keep in count-based mode (default: 100,000)
- Manual Cleanup: Use "Clean Logs Now" button for immediate cleanup
Settings -> Technical -> Logging Cleanup configuration page
Usage Examples
Time-Based Rotation Example
- Configure retention rules: DEBUG (3 days), INFO (7 days), WARNING (30 days), ERROR (90 days), CRITICAL (180 days)
- Enable "Log Cleanup Enabled" and select "Time-Based Rotation"
- Cron job runs daily and deletes logs older than their retention period
- Each log level is cleaned independently based on its retention rule
Count-Based Rotation Example
- Set "Max Records to Keep" to 100,000 (or your preferred limit)
- Select "Count-Based Rotation" mode
- When total log records exceed 100,000, oldest records are deleted
- Keeps the most recent 100,000 records regardless of log level
Manual Cleanup
- From Settings: Go to Settings -> Technical -> Logging Cleanup -> Click "Clean Logs Now"
- From Logs View: Open Technical -> Logging -> Click "Clean Logs Now" button
- Immediate cleanup using current configuration
- Notification shows number of deleted records
Logs list view showing the "Clean Logs Now" button
Technical Implementation
Architecture
- - ir.logging Model Extension: Adds cleanup_logs() method with time-based and count-based strategies
- - res.config.settings Extension: Configuration UI for retention policies and rotation modes
- - Scheduled Action: Daily cron job (ir.cron) for automated cleanup
- - Optimized SQL: Uses RETURNING clause for efficient deletion and accurate counts
- - Audit Logging: Creates log entries after each cleanup operation
Security & Safety
- Manual cleanup restricted to users with Technical Settings access (base.group_system)
- Configuration changes require appropriate permissions
- Safe transaction handling with proper commits
- Graceful error handling - cleanup failures don't break the system
- Audit trail for all cleanup operations
Performance Considerations
- Uses optimized SQL DELETE statements for bulk operations
- Minimal database load - cleanup runs during off-peak hours (configurable)
- Efficient per-level cleanup in time-based mode
- Subquery optimization for count-based mode
- No impact on active Odoo operations during cleanup
Report Issues & Contribute
Found a Bug?
If you encounter any bugs or issues with this module, please report them on our GitHub repository. This helps us improve the module for everyone.
- - Report Bugs: Create a bug report
- - Request Features: Suggest a new feature
- - Ask Questions: Get help with questions
- - View All Issues: Browse existing issues
Contributing
This module is open source and free for the community. We welcome contributions!
- Submit pull requests with improvements
- Report bugs and suggest features
- Help improve documentation
- Share your feedback and use cases
GitHub Repository: https://github.com/Tecpill/technical_os_odoo_apps
Support
For support and assistance, contact us at admin@tecpill.com
Credits
Please log in to comment on this module