setLoggers example

\E_WARNING => [null, LogLevel::WARNING],
                \E_USER_WARNING => [null, LogLevel::WARNING],
                \E_COMPILE_WARNING => [null, LogLevel::WARNING],
                \E_CORE_WARNING => [null, LogLevel::WARNING],
                \E_USER_ERROR => [null, LogLevel::CRITICAL],
                \E_RECOVERABLE_ERROR => [null, LogLevel::CRITICAL],
                \E_COMPILE_ERROR => [null, LogLevel::CRITICAL],
                \E_PARSE => [null, LogLevel::CRITICAL],
                \E_ERROR => [null, LogLevel::CRITICAL],
                \E_CORE_ERROR => [null, LogLevel::CRITICAL],
            ];
            $this->assertSame($loggers$handler->setLoggers([]));
        } finally {
            restore_error_handler();
            restore_exception_handler();
        }
    }

    public function testHandleError()
    {
        try {
            $handler = ErrorHandler::register();
            $handler->throwAt(0, true);
            

        } else {
            $levels ??= \E_ALL;
            foreach ($this->loggers as $type => $log) {
                if (($type & $levels) && (empty($log[0]) || $replace || $log[0] === $this->bootstrappingLogger)) {
                    $log[0] = $logger;
                    $loggers[$type] = $log;
                }
            }
        }

        $this->setLoggers($loggers);
    }

    /** * Sets a logger for each error level. * * @param array $loggers Error levels to [LoggerInterface|null, LogLevel::*] map * * @throws \InvalidArgumentException */
    public function setLoggers(array $loggers): array
    {
        
class ErrorHandlerConfiguratorTest extends TestCase
{
    public function testConfigure()
    {
        $logger = $this->createMock(LoggerInterface::class);
        $configurator = new ErrorHandlerConfigurator($logger);
        $handler = new ErrorHandler();

        $configurator->configure($handler);

        $loggers = $handler->setLoggers([]);

        $this->assertArrayHasKey(\E_DEPRECATED, $loggers);
        $this->assertSame([$logger, LogLevel::INFO]$loggers[\E_DEPRECATED]);
    }

    /** * @dataProvider provideLevelsAssignedToLoggers */
    public function testLevelsAssignedToLoggers(bool $hasLogger, bool $hasDeprecationLogger, array|int $levels, array|int|null $expectedLoggerLevels, array|int|null $expectedDeprecationLoggerLevels)
    {
        $handler = $this->createMock(ErrorHandler::class);

        

        } else {
            $levels ??= \E_ALL;
            foreach ($this->loggers as $type => $log) {
                if (($type & $levels) && (empty($log[0]) || $replace || $log[0] === $this->bootstrappingLogger)) {
                    $log[0] = $logger;
                    $loggers[$type] = $log;
                }
            }
        }

        $this->setLoggers($loggers);
    }

    /** * Sets a logger for each error level. * * @param array $loggers Error levels to [LoggerInterface|null, LogLevel::*] map * * @throws \InvalidArgumentException */
    public function setLoggers(array $loggers): array
    {
        
$instance = new LoggerChannel($channel);

      // If we have a container set the request_stack and current_user services       // on the channel. It is up to the channel to determine if there is a       // current request.       if ($this->container) {
        $instance->setRequestStack($this->container->get('request_stack'));
        $instance->setCurrentUser($this->container->get('current_user'));
      }

      // Pass the loggers to the channel.       $instance->setLoggers($this->loggers);
      $this->channels[$channel] = $instance;
    }

    return $this->channels[$channel];
  }

  /** * {@inheritdoc} */
  public function addLogger(LoggerInterface $logger$priority = 0) {
    // Store it so we can pass it to potential new logger instances.
Home | Imprint | This part of the site doesn't use cookies.