Setup log rotate for magento 2
Install Logrotate
# sudo apt-get update
# sudo apt-get install logrotate
Check version
logrotate --version
Add Logrotate directory
# sudo mkdir /var/www/html/var/log/logrotate
# sudo chown magento:www-data /var/www/html/var/log/logrotate
Add configuration file
sudo nano /etc/logrotate.d/magento2
Add content like
/var/www/html/var/log/*.log {
su magento www-data
weekly
missingok
# Rotate file if reach this size
minsize 50M
rotate 4
compress
notifempty
dateext
dateformat -%Y-%m-%d
create 664 magento www-data
olddir logrotate
}
Other usefull
# Rotate daily
daily
# Compress old log files
compress
# Keep the most recent log uncompressed
delaycompress
# Skip missing files
missingok
# Skip empty files
notifempty
# Rotate when the size is bigger than 50MB
size 1M
# Always keep 4 weeks of log files
rotate 1
# Create a new log file with mode 0644
create 0644
# Add a date extension to rotated files
dateext
# Sets the dateformat of the dateext
dateformat -%Y-%m-%d-%s
Test is working ?
sudo logrotate -f /etc/logrotate.d/magento2
REF & Thanks:
https://digitalstartup.co.uk/t/how-to-tidy-magento-2-log-files-using-logrotate/1526 https://linux.die.net/man/8/logrotate