Deployed my laravel application few months ago, and recently found out that my application was unable to write to log because my disk was full. When i checked i found out that the laravel.log file was almost huge. I want to know how to rotate the laravel logs with logrotate.
Asked
Active
Viewed 6,935 times
4
-
1How does your current logging configuration (`config/logging.php`) look like? – Namoshek Feb 09 '19 at 21:33
-
2Possible duplicate of [How to configure logrotate with php logs](https://stackoverflow.com/questions/14145812/how-to-configure-logrotate-with-php-logs). There are so many answers regarding logrotate already. Please use the search before asking a question. – Mike Doe Feb 09 '19 at 21:40
-
The file was _almost_ huge, XD. – ahpoblete Sep 06 '22 at 17:38
1 Answers
14
Go to /etc/logrotate.d and create a new config file.
cd /etc/logrotate.d
sudo touch laravel_rotate
Add the log file location and some settings.
log/file/dir/laravel_log.log {
monthly
missingok
rotate 12
compress
notifempty
create 755 www-data www-data
}
Settings explained:
- monthly: backups will be created monthly
- missingok: ignore the file if it is missing
- rotate 12: keep a year’s worth of backups
- notifempty: do not rotate the log if it’s empty
- compress: compress the log file
- create: create a replacement log file with the following permissions
To test this new config, run sudo logrotate --force laravel_rotate

Yan
- 349
- 2
- 9
-
1Great, also it is possible to rotate log files based on size. – zahra_oveyedzade Jan 27 '22 at 07:31