Download the PHP package alkhatibdev/logrotation without Composer
On this page you can find all versions of the php package alkhatibdev/logrotation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alkhatibdev/logrotation
More information about alkhatibdev/logrotation
Files in alkhatibdev/logrotation
Package logrotation
Short Description Laravel package for easy log rotation
License MIT
Homepage https://github.com/alkhatibdev/logrotation
Informations about the package logrotation
Laravel Log Rotation Package
This package makes log file rotation easier by automatically managing and organizing Laravel logs based on time and file size, retaining only the most recent logs (e.g., 12 months) and discarding older logs. This solution is ideal for applications that generate high volumes of logs, providing efficient log management and preventing excessive disk usage over time.
Benefits
- Rotates your log files based on date (monthly) or file size (size-based rotation).
- Retains logs for a configurable number of months (default: 12 months), which can be modified through the configuration file.
- Automatically deletes old logs after the configured retention period, freeing up disk space.
- Supports both compressed (
.gz) and uncompressed log files. - Helps prevent large log files from consuming excessive disk space during high-traffic periods.
Installation
Install the package via Composer:
Configuration & Advanced Customization
You can configure the log rotation behavior either via your .env file or programmatically using the LogRotator class.
Using .env file
Set the following variables in your .env file:
LOG_ROTATION_MAX_MONTHS: How many months of logs to keep before deletion.LOG_ROTATION_MAX_SIZE_KB: The size threshold for size-based rotation. When the log file exceeds this, a size-based archive is created.LOG_ROTATION_COMPRESS: Whether the archived logs should be compressed (.gz) or kept uncompressed (.log).
Note: You can still publish the configuration file if you want to override defaults or use dynamic configuration:
Programmatic Customization
You can fully customize log rotation by using the LogRotator class:
This merged approach allows you to configure the package using .env for most cases or fine-tune behavior programmatically when needed.
Usage
Log Rotation Scheduling
You can schedule log rotation in routes/console.php:
Or for Laravel 10.x and below, in app/Console/Kernel.php:
How it works:
- Scheduling daily ensures size-based rotation works properly, rotating large log files as soon as they exceed the configured size.
- Monthly rotation will still run only once per month — if the current month has already been rotated, it will be ignored until the next month.
- Optional: If you don’t want to enable size-based rotation, you can run the command
monthly()instead. This will rotate logs only once per month based on time, ignoring size increasing during the month.
Monthly Log Archives
The rotation creates a timestamped archive for the current file:
Size-Based Log Rotation
The package now supports automatic rotation when the log file exceeds a specified size. This is useful for high-traffic applications where a single month’s log may grow too large.
The rotation creates a timestamped archive for the current file:
Size-based logs are also subject to month-based retention and will be deleted if their month is older than the configured max_months.
Support
If you encounter any issues or have feature requests, feel free to open an issue on GitHub.
License
This package is open-sourced software licensed under the MIT license.