Shopware 6 - Deactivate exception logging

Shopware 6 logs all occurring PHP exceptions in the directory var/log according to the scheme: 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 confusing.

Shopware offers the option of defining a list of exceptions that should no longer be logged in the Shopware log via the configuration files.


In Shopware version 6.4.20.0 the hiding of 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 in the log 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""


Deactivation of the 404 error in the Shopware log

To deactivate the PHP exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException 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
        exclude_exception:
            - League\OAuth2\Server\Exception\OAuthServerException
            - Symfony\Component\HttpKernel\Exception\NotFoundHttpException


Further exceptions that should no longer be logged can be specified in the exclude_exception area. You can take the fully qualified name (Full Qualified Name) from the previous log, for example, and add it to this file.


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


Subsequently, no further exceptions of the class Symfony\Component\HttpKernel\Exception\NotFoundHttpException are logged in the Shopware log.