accentinteractive/laravel-logcleaner

Keep your laravel logs small and tidy.

v1.0.1 2021-04-26 13:55 UTC

This package is auto-updated.

Last update: 2021-09-27 07:26:12 UTC


README

Latest Version on Packagist Build Status Quality Score Total Downloads

Logs can get quite out of hand. This package helps save server space and keep your Laravel log files small.

  1. Trim your daily log to a given number of lines do it does not grow huge.
  2. Delete old daily logs, only keeping a given number of the latest log files.

Installation

You can install the package via composer:

composer require accentinteractive/laravel-logcleaner

Optionally you can publish the config file with:

php artisan vendor:publish --provider="Accentinteractive\LaravelLogcleaner\LaravelLogcleanerServiceProvider" --tag="config"

Usage

You can use logcleaner:run from the command line or set it as a cron job.

Command line usage;

// Get info about the command and options
php artisan logcleaner:run --help

// Trim big log files and delete old log files
php artisan logcleaner:run

// Pass the number of lines to keep when trimming log files. Overrides the config setting.
// This overrides the default set in config
php artisan logcleaner:run --keeplines=10000

// Pass the number of files to keep when deleting old log files. Overrides the config setting.
// This overrides the default set in config
php artisan logcleaner:run --keepfiles=7

// Run without actually cleaning any logs
php artisan logcleaner:run --dry-run

Cron job usage, add this to App\Console\Kernel:

protected function schedule(Schedule $schedule)
{
    $schedule->command('logcleaner:run')->daily()->at('01:00');
}

Of course, you can also pass options when defining a cron job.

protected function schedule(Schedule $schedule)
{
    $schedule->command('logcleaner:run', ['--keeplines' => 5000, '--keepfiles' => 14])->daily()->at('01:00');
}

Config settings

You can pass config settings to modify the behaviour.

  • log_files_to_keep : the number of log files to keep when deleting old log files. This config setting is overridden by option --keepfiles
  • log_lines_to_keep : the number of lines to leave intact when trimming log files. This config setting is overridden by option --keeplines
  • exclude : an array of filenames to exclude from processing, using wildcards.
  • trimming_enabled : enables log file trimming. true by default.
  • deleting_enabled : enables old log file deletions. true by default.

You can also pass options directly.

  • --keeplines=2000
  • --keepfiles=7
  • --dry-run

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email joost@accentinteractive.nl instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.