Shopware 6 - Log rotation / Logrotate
Shopware 6 logs all occurring PHP exceptions in the directory var/log
according to the scheme: prod-YYYY-MM-DD.log
. The Monolog Library is used for this purpose.
Unfortunately, Shopware does not offer an option for log rotation as standard, so two alternative options must be used:
- monolog rotating_file handler
- linux logrotate
Monolog rotating_file Handler
To use the monolog rotating_file handler in Shopware 6, a shopware.yaml config file must be created in the following Shopware directory:
/config/packages/shopware.yaml
Tip: With our managed Shopware servers, the correct document root directory is located under the absolute path: /var/www/vhosts/my-shop-domain.com/httpdocs/
# /var/www/vhosts/my-shop-domain.com/httpdocs/config/packages/shopware.yaml
shopware:
logger:
file_rotation_count: 14
The variable file_rotation_count
can be used to configure the maximum number of simultaneous log files. Older files are automatically removed by Monolog.
After the config file has been created, the Shopware cache must be emptied so that the new configuration file is activated:
bin/console cache:clear
Our Managed Shopware servers have various PHP binaries available for running the CLI console. To clear the cache with the PHP 8.1 CLI, the following command must be executed:
/opt/plesk/php/8.1/bin/php /var/www/vhosts/meine-shop-domain.de/httpdocs/bin/console cache:clear
Linux Logrotate
Navigate to the directory /etc/logrotate.d/
and create a new file using the command touch shopware
.
touch /etc/logrotate.d/shopware
/var/www/vhosts/shopware.creoline-demo.com/log/*.log {
daily
size 50M
rotate 14
notifempty
missingok
nocompress
}
The instruction daily
, rotate 14
instructs the logrotate daemon to rotate the Shopware log files daily for 14 days.