Shopware 6 - Disable Exception Logging

Shopware 6 logs all PHP exceptions that occur in the var/log directory using the following format: prod-YYYY-MM-DD.log. In a standard installation, all 404 errors (PHP exceptions) are also logged here, which can quickly make the log file difficult to read.

Shopware allows you to define a list of exceptions in the configuration files that should no longer be logged in the Shopware log.


In Shopware version 6.4.20.0, hiding selected exceptions does not work due to a bug. A patch for this has already been implemented and will be rolled out with the next Shopware release.



Example NotFoundException Log Entry

Shopware logs 404 errors as follows:

[2022-03-01T12:40:40.742311+00:00] request.ERROR: 

Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: 
"No route found for "GET https://shopware.creoline-demo.com/test-404-exception"


Disabling 404 Errors in the Shopware Log

To disable the PHP exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException in Shopware 6, you must create a shopware.yaml configuration file in the following Shopware directory:


/config/packages/shopware.yaml


Tip: On our Managed Shopware servers, the correct document root directory is located at the following absolute path: /var/www/vhosts/my-shop-domain.de/httpdocs/


# /var/www/vhosts/my-shop-domain.de/httpdocs/config/packages/shopware.yaml

shopware:
    logger:
 file_rotation_count: 14
 exclude_exception:
 - League\OAuth2\Server\Exception\OAuthServerException
 - Symfony\Component\HttpKernel\Exception\NotFoundHttpException


In the exclude_exception section, you can specify additional exceptions that should no longer be logged. You can find the fully qualified name (Full Qualified Name), for example, in the existing log and add it to this file.


After the configuration file has been created, the Shopware cache must be cleared so that the new configuration file takes effect:

bin/console cache:clear


On our Managed Shopware servers, various PHP binaries are available for running the CLI console. To clear the cache using the PHP 8.1 CLI, run the following command:

/opt/plesk/php/8.1/bin/php /var/www/vhosts/my-shop-domain.de/httpdocs/bin/console cache:clear


Afterward, no further exceptions of the class Symfony\Component\HttpKernel\Exception\NotFoundHttpException will be logged in the Shopware log.