This is a good question, Laravel now fills up the logs when an error occurs and the daemon is running.
I had a 400GB+ logfile when it could not connect to the DB and it kept trying overnight.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello. Can i set log rotation by log-file size? (Laravel 5.0.xx)
This is a good question, Laravel now fills up the logs when an error occurs and the daemon is running.
I had a 400GB+ logfile when it could not connect to the DB and it kept trying overnight.
Anyone? A simple way to limit the log file size for example would do.
I'm looking for solution about this too, any answer?
@super_simon @iTypo @mani95lisa why not just set a cronjob on the server to empty the log file?
Consider running this script every x seconds/minutes/hours/days/etc..
!#/bin/bash
file = /home/user/myapp.com/storage/logs/laravel.log # log file path
maxSize = 2048 #2MB - size in kilobytes
fileSize = $(du -k "$file" | cut -f 1)
if [ $fileSize -ge $maxSize]; then
echo "" > $file
fi
Note that the script above checks for the actual space being used by the file.
It might be easier to use the 'daily' log setting in config/app.php :
/*
|--------------------------------------------------------------------------
| Logging Configuration
|--------------------------------------------------------------------------
|
| Here you may configure the log settings for your application. Out of
| the box, Laravel uses the Monolog PHP logging library. This gives
| you a variety of powerful log handlers / formatters to utilize.
|
| Available Settings: "single", "daily", "syslog", "errorlog"
|
*/
'log' => 'single', // change this to daily
I would advice @ohffs solution too
Have you looked into logrotate? It will also do compression and limit the amount of logs as well.
@mani95lisa Logrotate is the best bet here.
@ohffs @Devmaurice if I'm not mistaken, that would create many log files. One per day. It won't delete the old one.
@nfauchelle @bashy well, that's also a solution. If he wants a pain free single log file he can just use cronjob and not over complicate such an easy task.
@kfirba I think it defaults to keeping only five days.
@ohffs Laravel? Yeah with logrotate you can set it up to how you want. Change it per week or per 3 days or how big it gets.
@bashy yeah - I think laravel's internal 'daily' option defaults to 5 days worth - possibly a bit easier than logrotate as you can config it within the app. Horses for courses though :-)
@kfirba thanks, my logs filled by Redis errors which caused by queue. I set --tries=3, but the Redis errors been logged forever, like a endless loop. I have fixed below bug about redis, but have no idea about endless loop errors.
RedisError: MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled
So I'm thinking to limit the max size of logs, to keep the disk space low.
Cron is a good idea, thanks again! I'll try to use shell to limit logs folder's size.
@ohffs the point is endless error logs fill up disk space, not the way log saved, I use daily log too, thanks.
@mani95lisa it sounds like you should be fixing that bug rather than dealing with the logs ;-) Your redis install is probably trying to save it's backup to a directory it doesn't have permissions on :-) Have a look in your redis.conf file and see where it's pointing to (the path is under the 'working directory' section of the config file).
Indeed it has nothing to do with daily, or limit the amount of log files, i'm already using that.
The problem is when for example mysqld goes does in the middle of the night, and you have many laravel queue workers they start generating thousands of errors filling up the disk real fast.
We need a setting to limit the log file SIZE. Or some way when its repeating the same error thousands of times, maybe just use a counter instead of the whole error msg?
@iTypo Manage that yourself!! Use logrotate https://support.rackspace.com/how-to/understanding-logrotate-utility/
@ohffs thanks, I have fixed that bug.
@bashy thanks, use logrotate to limit the size maybe is the best way.
@iTypo https://serversforhackers.com/managing-logs-with-logrotate this article have a sample.
I know i can manage it myself, but laravel offers very nice features like daily logs, limit number of logs, wouldent it be nice if it also had an out of the box feature which prevents your server from going down because of laravel error looping? (creating 400GB+ logs overnight)
I think it would be a great addition to laravel instead of just saying go manage it yourself using X external tool.
Please or to participate in this conversation.