Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ErrorHandler.php

function ErrorHandler::setLoggers

Sets a logger for each error level.

Parameters

array $loggers Error levels to [LoggerInterface|null, LogLevel::*] map:

Throws

\InvalidArgumentException

1 call to ErrorHandler::setLoggers()
ErrorHandler::setDefaultLogger in vendor/symfony/error-handler/ErrorHandler.php
Sets a logger to non assigned errors levels.

File

vendor/symfony/error-handler/ErrorHandler.php, line 238

Class

ErrorHandler
A generic ErrorHandler for the PHP engine.

Namespace

Symfony\Component\ErrorHandler

Code

public function setLoggers(array $loggers) : array {
    $prevLogged = $this->loggedErrors;
    $prev = $this->loggers;
    $flush = [];
    foreach ($loggers as $type => $log) {
        if (!isset($prev[$type])) {
            throw new \InvalidArgumentException('Unknown error type: ' . $type);
        }
        if (!\is_array($log)) {
            $log = [
                $log,
            ];
        }
        elseif (!\array_key_exists(0, $log)) {
            throw new \InvalidArgumentException('No logger provided.');
        }
        if (null === $log[0]) {
            $this->loggedErrors &= ~$type;
        }
        elseif ($log[0] instanceof LoggerInterface) {
            $this->loggedErrors |= $type;
        }
        else {
            throw new \InvalidArgumentException('Invalid logger provided.');
        }
        $this->loggers[$type] = $log + $prev[$type];
        if ($this->bootstrappingLogger && $prev[$type][0] === $this->bootstrappingLogger) {
            $flush[$type] = $type;
        }
    }
    $this->reRegister($prevLogged | $this->thrownErrors);
    if ($flush) {
        foreach ($this->bootstrappingLogger
            ->cleanLogs() as $log) {
            $type = ThrowableUtils::getSeverity($log[2]['exception']);
            if (!isset($flush[$type])) {
                $this->bootstrappingLogger
                    ->log($log[0], $log[1], $log[2]);
            }
            elseif ($this->loggers[$type][0]) {
                $this->loggers[$type][0]
                    ->log($this->loggers[$type][1], $log[1], $log[2]);
            }
        }
    }
    return $prev;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal