Jesús Amieiro

How to rotate the Laravel logs

Laravel stores the logs of the project in the file “storage/logs/laravel.log”. If you don’t rotate this file can increase its size a lot, using the most part of the storage, causing problems with a full disk.

To avoid these problems you can add this project to the logrotate of your server. You have to add a new file in the “/etc/logrotate.d/” folder:

$ sudo touch /etc/logrotate.d/my-proyect

Then you have to add the config in this file:

/var/my-project/storage/logs/laravel.log {
    weekly
    missingok
    rotate 12
    compress
    notifempty
    su my-user my-group
    create 700 my-user my-group
}

Now I explain the parameters:

To check this config file you can execute the next command (in debug mode):

$ logrotate -d /etc/logrotate.d/my-proyect

You can find more information with the man command:

$ man logrotate

and in those links:

Exit mobile version