I have migrated an application from Symfony 3.4 to Symfony 4.4.
Now I have a lot of deprecations for each request/ Sf command (I can't fix that deprecations).
How can I exclude deprecations from the log for this Symfony App?
I have migrated an application from Symfony 3.4 to Symfony 4.4.
Now I have a lot of deprecations for each request/ Sf command (I can't fix that deprecations).
How can I exclude deprecations from the log for this Symfony App?
Exclude the php
channel from the log handler:
Eg. config/packages/prod/monolog.yaml
:
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
formatter: monolog.formatter.session_request
channels:
- '!php' # <----------- add this line
Leave deprecation messages in the dev
mode though. You should be aware of the changes in upstream packages.
PS. in newer Symfony versions you have to exclude the deprecation
channel instead, i.e.:
channels:
- '!deprecation'
What works for me in Symfony 6.1.X, is setting it the deprecation
channel and type to "null"
. This will make sure the deprecation messages will not show up in the logging but still be available to see from the debug toolbar.
# config/packages/dev/monolog.yaml
monolog:
channels:
- deprecation
handlers:
deprecation:
type: "null"
channels: [deprecation]
Work for me Symfony 5.4+
add in channels list 'deprecation', and use in handles argument '!deprecation'
its work filter example:
monolog:
channels:
- 'deprecation'
handlers:
main:
type: rotating_file
max_files: 30
path: '%kernel.logs_dir%/%kernel.environment%.log'
level: debug
channels: ['!event', '!doctrine', '!deprecation']
Set the following env variable (eg. in .env.local):
SYMFONY_DEPRECATIONS_HELPER=weak
The error handlers are controlled by Symfony\Component\HttpKernel\EventListener\DebugHandlersListener
Error levels that should be logged are defined by the constructor argument $levels = \E_ALL
which is by default E_ALL
. Unfortunately the value is static in the service definition. But you can override it by a compiler pass and introduce a parameter php_log_level
:
<?php
declare(strict_types=1);
namespace YourBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class PhpErrorLevelCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if(! $container->hasDefinition('debug.debug_handlers_listener') || ! $container->hasParameter('php_log_level')) {
return;
}
$container
->findDefinition('debug.debug_handlers_listener')
->replaceArgument(
2,
(int) $container->getParameter('php_log_level')
);
}
}
This compiler pass is registered in your bundle:
<?php
declare(strict_types=1);
namespace YourBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use YourBundle\DependencyInjection\PhpErrorLevelCompilerPass;
class YourBundle extends Bundle {
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new PhpErrorLevelCompilerPass());
}
}
In your parameters file you can then set the value to E_ALL & ~ E_DEPRECATED & ~ E_USER_DEPRECATED
which is 8191
:
php_log_level: 8191
Note that this applies for Symfony 3.4 and 4.4.
© 2022 - 2024 — McMap. All rights reserved.
php.INFO: User Deprecated:
– Uranometry