diff --git a/core/core.services.yml b/core/core.services.yml index ed3e936..f8c4163 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -138,8 +138,7 @@ services: - { name: needs_destruction } logger.factory: class: Drupal\Core\Logger\LoggerChannelFactory - calls: - - [setContainer, ['@service_container']] + parent: container.trait logger.channel.default: class: Drupal\Core\Logger\LoggerChannel factory_method: get diff --git a/core/lib/Drupal/Core/Logger/LoggerChannelFactory.php b/core/lib/Drupal/Core/Logger/LoggerChannelFactory.php index 58c01ba..1ec1710 100644 --- a/core/lib/Drupal/Core/Logger/LoggerChannelFactory.php +++ b/core/lib/Drupal/Core/Logger/LoggerChannelFactory.php @@ -8,13 +8,15 @@ namespace Drupal\Core\Logger; use Psr\Log\LoggerInterface; -use Symfony\Component\DependencyInjection\ContainerAware; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; +use Symfony\Component\DependencyInjection\ContainerAwareTrait; use Symfony\Component\DependencyInjection\Exception\RuntimeException; /** * Defines a factory for logging channels. */ -class LoggerChannelFactory extends ContainerAware implements LoggerChannelFactoryInterface { +class LoggerChannelFactory implements LoggerChannelFactoryInterface, ContainerAwareInterface { + use ContainerAwareTrait; /** * Array of all instantiated logger channels keyed by channel name. @@ -37,13 +39,16 @@ public function get($channel) { if (!isset($this->channels[$channel])) { $instance = new LoggerChannel($channel); - // If the request is available, set it with the current user to the channel. - try { - $instance->setRequest($this->container->get('request')); - $instance->setCurrentUser($this->container->get('current_user')); - } - catch (RuntimeException $e) { - // We are not in a request context. + // If the service container is set and request is available, set it with + // the current user to the channel. + if ($this->container) { + try { + $instance->setRequest($this->container->get('request')); + $instance->setCurrentUser($this->container->get('current_user')); + } + catch (RuntimeException $e) { + // We are not in a request context. + } } // Pass the loggers to the channel. diff --git a/core/tests/Drupal/Tests/Core/Logger/LoggerChannelFactoryTest.php b/core/tests/Drupal/Tests/Core/Logger/LoggerChannelFactoryTest.php index 23f2ef6..9c29831 100644 --- a/core/tests/Drupal/Tests/Core/Logger/LoggerChannelFactoryTest.php +++ b/core/tests/Drupal/Tests/Core/Logger/LoggerChannelFactoryTest.php @@ -47,7 +47,7 @@ public static function getInfo() { } /** - * Test for LoggerChannelFactory::get() + * Tests LoggerChannelFactory::get(). * * @covers ::get */ diff --git a/core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php b/core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php index 817f935..c62cf41 100644 --- a/core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php +++ b/core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php @@ -47,7 +47,7 @@ public static function getInfo() { } /** - * Test for LoggerChannel::log() + * Tests LoggerChannel::log(). * * @param callable $expected * An anonymous function to use with $this->callback() of the logger mock. @@ -80,7 +80,7 @@ public function testLog(callable $expected, Request $request = NULL, AccountInte } /** - * Test for LoggerChannel::addLoggers() + * Tests LoggerChannel::addLoggers(). * * @covers ::addLogger * @covers ::sortLoggers