You are here

class MonologServiceProvider in Monolog 8

Same name and namespace in other branches
  1. 2.x src/MonologServiceProvider.php \Drupal\monolog\MonologServiceProvider

Overrides the logger.factory service with the monolog factory.

Hierarchy

Expanded class hierarchy of MonologServiceProvider

File

src/MonologServiceProvider.php, line 12

Namespace

Drupal\monolog
View source
class MonologServiceProvider extends ServiceProviderBase {

  /**
   * {@inheritdoc}
   */
  public function alter(ContainerBuilder $container) {
    $definition = $container
      ->getDefinition('logger.factory');
    $definition
      ->setClass('Drupal\\monolog\\Logger\\MonologLoggerChannelFactory')
      ->clearTags();

    // Allow existing Drupal loggers to be added as handlers.
    $drupalLoggers = $container
      ->findTaggedServiceIds('logger');
    foreach ($drupalLoggers as $id => $tags) {
      $handlerId = sprintf('monolog.handler.drupal.%s', preg_replace('/^logger\\./', '', $id));

      // Allow the handler to be explicitly defined elsewhere.
      if (!$container
        ->has($handlerId)) {
        $definition = $container
          ->register($handlerId, 'Drupal\\monolog\\Logger\\Handler\\DrupalHandler');
        $definition
          ->addArgument(new Reference($id));
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MonologServiceProvider::alter public function Modifies existing service definitions. Overrides ServiceProviderBase::alter
ServiceProviderBase::register public function Registers services to the container. Overrides ServiceProviderInterface::register 1