Commit e6a360be authored by catch's avatar catch

Issue #2571521 by Maouna, dawehner, sdstyles: Make the logger available on the controllerBase

parent 702137d9
......@@ -112,6 +112,13 @@ abstract class ControllerBase implements ContainerInjectionInterface {
*/
protected $formBuilder;
/**
* The logger factory.
*
* @var \Psr\Log\LoggerInterface
*/
protected $loggerFactory;
/**
* {@inheritdoc}
*/
......@@ -282,6 +289,23 @@ protected function languageManager() {
return $this->languageManager;
}
/**
* Returns a channel logger object.
*
* @param string $channel
* The name of the channel. Can be any string, but the general practice is
* to use the name of the subsystem calling this.
*
* @return \Psr\Log\LoggerInterface
* The logger for this channel.
*/
protected function getLogger($channel) {
if (!$this->loggerFactory) {
$this->loggerFactory = $this->container()->get('logger.factory');
}
return $this->loggerFactory->get($channel);
}
/**
* Returns the service container.
*
......
......@@ -53,13 +53,11 @@ class ImageStyleDownloadController extends FileDownloadController {
* The lock backend.
* @param \Drupal\Core\Image\ImageFactory $image_factory
* The image factory.
* @param \Psr\Log\LoggerInterface $logger
* A logger instance.
*/
public function __construct(LockBackendInterface $lock, ImageFactory $image_factory, LoggerInterface $logger) {
public function __construct(LockBackendInterface $lock, ImageFactory $image_factory) {
$this->lock = $lock;
$this->imageFactory = $image_factory;
$this->logger = $logger;
$this->logger = $this->getLogger('image');
}
/**
......@@ -68,8 +66,7 @@ public function __construct(LockBackendInterface $lock, ImageFactory $image_fact
public static function create(ContainerInterface $container) {
return new static(
$container->get('lock'),
$container->get('image.factory'),
$container->get('logger.factory')->get('image')
$container->get('image.factory')
);
}
......
......@@ -47,14 +47,12 @@ class SearchController extends ControllerBase {
*
* @param \Drupal\search\SearchPageRepositoryInterface $search_page_repository
* The search page repository.
* @param \Psr\Log\LoggerInterface $logger
* A logger instance.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
*/
public function __construct(SearchPageRepositoryInterface $search_page_repository, LoggerInterface $logger, RendererInterface $renderer) {
public function __construct(SearchPageRepositoryInterface $search_page_repository, RendererInterface $renderer) {
$this->searchPageRepository = $search_page_repository;
$this->logger = $logger;
$this->logger = $this->getLogger('search');
$this->renderer = $renderer;
}
......@@ -64,7 +62,6 @@ public function __construct(SearchPageRepositoryInterface $search_page_repositor
public static function create(ContainerInterface $container) {
return new static(
$container->get('search.search_page_repository'),
$container->get('logger.factory')->get('search'),
$container->get('renderer')
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment