sanjeev-kr / magento2-logrotation
magento 2 extension automatically and manually rotates and gzip-compresses Magento log files in the var/log directory.
Package info
github.com/sanjeev-kr/magento2-logrotation
Type:magento2-module
pkg:composer/sanjeev-kr/magento2-logrotation
Requires
- php: >=8.0.0
This package is auto-updated.
Last update: 2026-07-23 09:45:10 UTC
README
A production-ready Magento 2 module that automatically and manually rotates and gzip-compresses Magento log files in the var/log directory.
Features
- Automated Daily Log Rotation: Automatically rotates
.logfiles daily at 1:00 AM via Magento cron (0 1 * * *). - Manual CLI Command: Trigger log rotation on demand via command line interface (
bin/magento sanjeev:logrotation:rotate). - Gzip Streaming Compression: Rotates logs to timestamped files (
filename-YYYY-MM-DD-HHMMSS.log) and compresses them to.gzformat using chunked streaming for low memory usage. - Permission & Ownership Retention: Preserves file permissions and ownership on newly created empty log files.
- Security & Safety: Checks file paths to prevent directory traversal and gracefully handles missing files, file locks, or errors without interrupting ongoing logging or cron execution.
- Custom Logging: Operational progress and rotation statistics are logged to
var/log/sanjeev_logrotation.log.
Admin Permissions & Access Control (ACL)
Access to the module's configuration settings in Magento Admin is protected by standard Magento 2 Access Control Lists (ACL).
- ACL Resource ID:
Sanjeev_Logrotation::config - Navigation Path in Admin:
Stores → Configuration → Advanced → Log Rotation
Only administrator roles granted the Sanjeev_Logrotation::config resource (or full Admin access) can view and modify these settings.
Installation
Follow these steps to install and enable the module:
-
Place module files in the following directory:
app/code/Sanjeev/Logrotation
-
Enable the module:
php bin/magento module:enable Sanjeev_Logrotation
-
Run setup upgrade to register the module:
php bin/magento setup:upgrade
-
Compile dependency injection:
php bin/magento setup:di:compile
-
Flush Magento cache:
php bin/magento cache:flush
Configuration
Navigate to Stores → Configuration → Advanced → Log Rotation in the Magento Admin panel:
- Enable Log Rotation:
Yes(Default): Automated cron job and CLI command will perform log rotation.No: Disables log rotation. Cron job will exit immediately without processing any files.
How to Use
1. Automated Execution (Cron)
Once enabled, Magento cron will execute the log rotation automatically every day at 1:00 AM according to the schedule defined in crontab.xml:
<schedule>0 1 * * *</schedule>
2. Manual Execution (CLI Command)
To manually trigger log rotation at any time from your server command line, run:
php bin/magento sanjeev:logrotation:rotate
Output Example:
Starting log rotation process...
Log rotation process completed successfully.
Uninstallation
To safely disable and remove the module from your Magento store:
-
Disable the module:
php bin/magento module:disable Sanjeev_Logrotation
-
Run setup upgrade:
php bin/magento setup:upgrade
-
Re-compile DI:
php bin/magento setup:di:compile
-
(Optional) Remove the module directory from file system:
rm -rf app/code/Sanjeev/Logrotation
-
Flush Magento cache:
php bin/magento cache:flush
License & Copyright
Copyright (c) 2026 Sanjeev Kumar
Licensed under the MIT License.