You are here

class Redirect404LogSuppressor in Redirect 8

Allows 'page not found' events to be suppressed by returning a NullLogger.

Hierarchy

Expanded class hierarchy of Redirect404LogSuppressor

1 string reference to 'Redirect404LogSuppressor'
redirect_404.services.yml in modules/redirect_404/redirect_404.services.yml
modules/redirect_404/redirect_404.services.yml
1 service uses Redirect404LogSuppressor
logger.redirect_404 in modules/redirect_404/redirect_404.services.yml
\Drupal\redirect_404\Render\Redirect404LogSuppressor

File

modules/redirect_404/src/Render/Redirect404LogSuppressor.php, line 15

Namespace

Drupal\redirect_404\Render
View source
class Redirect404LogSuppressor implements LoggerChannelFactoryInterface {
  use DependencySerializationTrait;

  /**
   * The logger channel factory.
   *
   * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
   */
  protected $loggerChannelFactory;

  /**
   * The configuration factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Constructs a Redirect404LogSuppressor object.
   *
   * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_channel_factory
   *   The logger channel factory.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The configuration factory.
   */
  public function __construct(LoggerChannelFactoryInterface $logger_channel_factory, ConfigFactoryInterface $config_factory) {
    $this->loggerChannelFactory = $logger_channel_factory;
    $this->configFactory = $config_factory;
  }

  /**
   * {@inheritdoc}
   */
  public function get($channel) {
    if ($channel == 'page not found' && $this->configFactory
      ->get('redirect_404.settings')
      ->get('suppress_404')) {

      // Do not log if a 404 error is detected and the suppress_404 is enabled.
      return new NullLogger();
    }

    // Call LoggerChannelFactory to let the default logger workflow proceed.
    return $this->loggerChannelFactory
      ->get($channel);
  }

  /**
   * {@inheritdoc}
   */
  public function addLogger(LoggerInterface $logger, $priority = 0) {
    $this->loggerChannelFactory
      ->addLogger($logger, $priority);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
Redirect404LogSuppressor::$configFactory protected property The configuration factory.
Redirect404LogSuppressor::$loggerChannelFactory protected property The logger channel factory.
Redirect404LogSuppressor::addLogger public function Adds a logger to all the channels. Overrides LoggerChannelFactoryInterface::addLogger
Redirect404LogSuppressor::get public function Retrieves the registered logger for the requested channel. Overrides LoggerChannelFactoryInterface::get
Redirect404LogSuppressor::__construct public function Constructs a Redirect404LogSuppressor object.