Keep Logs Tidy With the Log Cleaner Package for Laravel
Published on by Paul Redmond
Laravel Log Cleaner is a package by Joost van Veen for keeping your log files small and tidy. While there are various ways to keep log file size tidy in production, this package uses the built-in Artisan console that you can run manually, via cron directly, or through the scheduler:
$schedule ->command('logcleaner:run', [ '--keeplines' => 5000, '--keepfiles' => 14 ]) ->daily() ->at('01:00');
Log cleaner provides configurations you can set in your environment or override in the command. The main configuration features and console options include:
- Specify the number of files to keep
- Specify the number of lines to keep
- Exclude pattern to exclude file patterns from processing
- Log file trimming (enabled by default, configurable)
- Configurable file deletion enabled/disabled
Here are some console command examples from the readme that give you a nice visualization of how to use this console command:
# Get info about the command and optionsphp artisan logcleaner:run --help # Trim big log files and delete old log filesphp artisan logcleaner:run # Pass the number of lines to keep when trimming log files. Overrides the config setting.# This overrides the default set in configphp 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 configphp artisan logcleaner:run --keepfiles=7 # Run without actually cleaning any logsphp artisan logcleaner:run --dry-run
You can learn more about this package, get full installation instructions, and view the source code on GitHub.
This package was submitted to our Laravel News Links section. Links is a place the community can post packages and tutorials around the Laravel ecosystem. Follow along on Twitter @LaravelLinks