diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterLoggersPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterLoggersPass.php index 087275b..3b6a82c 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterLoggersPass.php +++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterLoggersPass.php @@ -21,10 +21,6 @@ public function process(ContainerBuilder $container) { $definitions = array(); foreach ($container->findTaggedServiceIds('logger_channel') as $id => $attributes) { $definition = $container->getDefinition($id); - // Set the request object. - $definition->addMethodCall('setRequest', array(new Reference('request', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))); - // Set the current_user object. - $definition->addMethodCall('setCurrentUser', array(new Reference('current_user', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))); $definitions[] = $definition; } // Loop through all available logger services (eg dblog, syslog) and add diff --git a/core/lib/Drupal/Core/Logger/LoggerChannelFactory.php b/core/lib/Drupal/Core/Logger/LoggerChannelFactory.php index 397521b..917aad7 100644 --- a/core/lib/Drupal/Core/Logger/LoggerChannelFactory.php +++ b/core/lib/Drupal/Core/Logger/LoggerChannelFactory.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Logger; use Symfony\Component\DependencyInjection\ContainerAware; +use Symfony\Component\DependencyInjection\Exception\RuntimeException; /** * Defines a factory for logging channels. @@ -25,10 +26,22 @@ class LoggerChannelFactory extends ContainerAware { public function getLogger($channel) { $channel_service = 'logger.channel.' . str_replace(' ', '_', $channel); if ($this->container->has($channel_service)) { - return $this->container->get($channel_service); + $logger = $this->container->get($channel_service); + } + else { + $logger = $this->container->get('logger.channel.default'); + } + + // If the request is available, set it with the current user to the logger. + try { + $logger->setRequest($this->container->get('request')); + $logger->setCurrentUser($this->container->get('current_user')); + } + catch (RuntimeException $e) { + // We are not in a request context. } - return $this->container->get('logger.channel.default'); + return $logger; } }