AddDebugLogProcessorPass.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Reference;
  14. class AddDebugLogProcessorPass implements CompilerPassInterface
  15. {
  16. public function process(ContainerBuilder $container)
  17. {
  18. if (!$container->hasDefinition('profiler')) {
  19. return;
  20. }
  21. if (!$container->hasDefinition('monolog.logger_prototype')) {
  22. return;
  23. }
  24. if (!$container->hasDefinition('debug.log_processor')) {
  25. return;
  26. }
  27. $definition = $container->getDefinition('monolog.logger_prototype');
  28. $definition->setConfigurator([__CLASS__, 'configureLogger']);
  29. $definition->addMethodCall('pushProcessor', [new Reference('debug.log_processor')]);
  30. }
  31. public static function configureLogger($logger)
  32. {
  33. if (\is_object($logger) && method_exists($logger, 'removeDebugLogger') && \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
  34. $logger->removeDebugLogger();
  35. }
  36. }
  37. }