Skip to content

Document the option to map PHP errors to log levels #15461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions reference/configuration/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2845,6 +2845,69 @@ Use the application logger instead of the PHP logger for logging PHP errors.
When an integer value is used, it also sets the log level. Those integer
values must be the same used in the `error_reporting PHP option`_.

This option also accepts a map of PHP errors to log levels:

.. configuration-block::

.. code-block:: yaml

# config/packages/framework.yaml
framework:
php_errors:
log:
'!php/const \E_DEPRECATED': !php/const Psr\Log\LogLevel::ERROR
'!php/const \E_USER_DEPRECATED': !php/const Psr\Log\LogLevel::ERROR
'!php/const \E_NOTICE': !php/const Psr\Log\LogLevel::ERROR
'!php/const \E_USER_NOTICE': !php/const Psr\Log\LogLevel::ERROR
'!php/const \E_STRICT': !php/const Psr\Log\LogLevel::ERROR
'!php/const \E_WARNING': !php/const Psr\Log\LogLevel::ERROR
'!php/const \E_USER_WARNING': !php/const Psr\Log\LogLevel::ERROR
'!php/const \E_COMPILE_WARNING': !php/const Psr\Log\LogLevel::ERROR
'!php/const \E_CORE_WARNING': !php/const Psr\Log\LogLevel::ERROR
'!php/const \E_USER_ERROR': !php/const Psr\Log\LogLevel::CRITICAL
'!php/const \E_RECOVERABLE_ERROR': !php/const Psr\Log\LogLevel::CRITICAL
'!php/const \E_COMPILE_ERROR': !php/const Psr\Log\LogLevel::CRITICAL
'!php/const \E_PARSE': !php/const Psr\Log\LogLevel::CRITICAL
'!php/const \E_ERROR': !php/const Psr\Log\LogLevel::CRITICAL
'!php/const \E_CORE_ERROR': !php/const Psr\Log\LogLevel::CRITICAL

.. code-block:: xml

<!-- config/packages/framework.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<!-- in XML configuration you cannot use PHP constants as the value of
the 'type' attribute, which makes this format way less readable.
Consider using YAML or PHP for this configuration -->
<framework:log type="8" logLevel="error"/>
<framework:log type="2" logLevel="error"/>
<!-- ... -->
</framework:config>
</container>

.. code-block:: php

// config/packages/framework.php
use Psr\Log\LogLevel;
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework) {
$framework->phpErrors()->log(\E_DEPRECATED, LogLevel::ERROR);
$framework->phpErrors()->log(\E_USER_DEPRECATED, LogLevel::ERROR);
// ...
};

.. versionadded:: 5.3

The option to map PHP errors to log levels was introduced in Symfony 5.3.

throw
.....

Expand Down