summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2014-07-31 12:44:46 (GMT)
committerNathaniel Catchpole2014-07-31 12:46:06 (GMT)
commita91ef2b8538f2a03fd704d2ac0d906234750c7a4 (patch)
treed01597718ff8ed98066e8d1d1c9ba9450042f8c4
parentced85d104ad34336a251ea8eb9fc322aae940746 (diff)
Issue #2272481 by herom, ParisLiakos, tim.plunkett: Remove usages of watchdog() from forms, plugins and controllers.
-rw-r--r--core/core.services.yml8
-rw-r--r--core/lib/Drupal.php2
-rw-r--r--core/lib/Drupal/Core/Form/FormBase.php23
-rw-r--r--core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php18
-rw-r--r--core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php15
-rw-r--r--core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php13
-rw-r--r--core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php15
-rw-r--r--core/modules/action/src/Form/ActionDeleteForm.php2
-rw-r--r--core/modules/action/src/Plugin/Action/EmailAction.php20
-rw-r--r--core/modules/aggregator/src/FeedForm.php2
-rw-r--r--core/modules/aggregator/src/Form/FeedDeleteForm.php2
-rw-r--r--core/modules/aggregator/src/Form/OpmlFeedAdd.php2
-rw-r--r--core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php18
-rw-r--r--core/modules/ban/src/Form/BanDelete.php2
-rw-r--r--core/modules/block_content/src/BlockContentForm.php7
-rw-r--r--core/modules/block_content/src/BlockContentTypeForm.php5
-rw-r--r--core/modules/block_content/src/Form/BlockContentDeleteForm.php2
-rw-r--r--core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php2
-rw-r--r--core/modules/book/src/Form/BookAdminEditForm.php2
-rw-r--r--core/modules/comment/src/CommentForm.php7
-rw-r--r--core/modules/comment/src/Form/ConfirmDeleteMultiple.php2
-rw-r--r--core/modules/comment/src/Form/DeleteForm.php2
-rw-r--r--core/modules/contact/src/CategoryForm.php4
-rw-r--r--core/modules/contact/src/Form/CategoryDeleteForm.php2
-rw-r--r--core/modules/contact/src/MessageForm.php4
-rw-r--r--core/modules/filter/src/Plugin/Filter/FilterNull.php2
-rw-r--r--core/modules/forum/src/Form/DeleteForm.php2
-rw-r--r--core/modules/forum/src/Form/ForumForm.php4
-rw-r--r--core/modules/image/src/Controller/ImageStyleDownloadController.php20
-rw-r--r--core/modules/image/src/Entity/ImageStyle.php4
-rw-r--r--core/modules/image/src/ImageEffectBase.php27
-rw-r--r--core/modules/image/src/Plugin/ImageEffect/CropImageEffect.php2
-rw-r--r--core/modules/image/src/Plugin/ImageEffect/DesaturateImageEffect.php2
-rw-r--r--core/modules/image/src/Plugin/ImageEffect/ResizeImageEffect.php2
-rw-r--r--core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php2
-rw-r--r--core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php2
-rw-r--r--core/modules/image/src/Plugin/ImageEffect/ScaleImageEffect.php2
-rw-r--r--core/modules/locale/src/Form/TranslateEditForm.php2
-rw-r--r--core/modules/menu_ui/src/Form/MenuDeleteForm.php2
-rw-r--r--core/modules/menu_ui/src/MenuForm.php4
-rw-r--r--core/modules/node/src/Form/DeleteMultiple.php2
-rw-r--r--core/modules/node/src/Form/NodeDeleteForm.php2
-rw-r--r--core/modules/node/src/Form/NodeRevisionDeleteForm.php2
-rw-r--r--core/modules/node/src/Form/NodeRevisionRevertForm.php2
-rw-r--r--core/modules/node/src/Form/NodeTypeDeleteConfirm.php2
-rw-r--r--core/modules/node/src/NodeForm.php6
-rw-r--r--core/modules/node/src/NodeTypeForm.php3
-rw-r--r--core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php2
-rw-r--r--core/modules/responsive_image/src/ResponsiveImageMappingForm.php2
-rw-r--r--core/modules/rest/src/Plugin/ResourceBase.php16
-rw-r--r--core/modules/rest/src/Plugin/rest/resource/EntityResource.php6
-rw-r--r--core/modules/search/src/Controller/SearchController.php18
-rw-r--r--core/modules/system/src/Controller/FormAjaxController.php33
-rw-r--r--core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php2
-rw-r--r--core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php2
-rw-r--r--core/modules/taxonomy/src/Form/TermDeleteForm.php2
-rw-r--r--core/modules/taxonomy/src/Form/VocabularyDeleteForm.php2
-rw-r--r--core/modules/taxonomy/src/Form/VocabularyResetForm.php2
-rw-r--r--core/modules/taxonomy/src/TermForm.php4
-rw-r--r--core/modules/taxonomy/src/VocabularyForm.php4
-rw-r--r--core/modules/user/src/Form/UserCancelForm.php2
-rw-r--r--core/modules/user/src/Form/UserLoginForm.php4
-rw-r--r--core/modules/user/src/Form/UserPasswordForm.php2
-rw-r--r--core/modules/user/src/Form/UserRoleDelete.php2
-rw-r--r--core/modules/user/src/RegisterForm.php2
-rw-r--r--core/modules/user/src/RoleForm.php4
-rw-r--r--core/tests/Drupal/Tests/Core/Image/ImageTest.php3
67 files changed, 292 insertions, 101 deletions
diff --git a/core/core.services.yml b/core/core.services.yml
index fd9028c..a58f779 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -176,6 +176,11 @@ services:
factory_method: get
factory_service: logger.factory
arguments: ['system']
+ logger.channel.image:
+ class: Drupal\Core\Logger\LoggerChannel
+ factory_method: get
+ factory_service: logger.factory
+ arguments: ['image']
logger.log_message_parser:
class: Drupal\Core\Logger\LogMessageParser
@@ -741,9 +746,10 @@ services:
- { name: event_subscriber }
image.toolkit.manager:
class: Drupal\Core\ImageToolkit\ImageToolkitManager
- arguments: ['@container.namespaces', '@cache.discovery', '@config.factory', '@module_handler', '@image.toolkit.operation.manager']
+ arguments: ['@container.namespaces', '@cache.discovery', '@config.factory', '@module_handler', '@image.toolkit.operation.manager', '@logger.channel.image']
image.toolkit.operation.manager:
class: Drupal\Core\ImageToolkit\ImageToolkitOperationManager
+ arguments: ['@logger.channel.image']
parent: default_plugin_manager
image.factory:
class: Drupal\Core\Image\ImageFactory
diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php
index 6595e6f..b5e27de 100644
--- a/core/lib/Drupal.php
+++ b/core/lib/Drupal.php
@@ -640,7 +640,7 @@ class Drupal {
* The name of the channel. Can be any string, but the general practice is
* to use the name of the subsystem calling this.
*
- * @return \Drupal\Core\Logger\LoggerChannelInterface
+ * @return \Psr\Log\LoggerInterface
* The logger for this channel.
*/
public static function logger($channel) {
diff --git a/core/lib/Drupal/Core/Form/FormBase.php b/core/lib/Drupal/Core/Form/FormBase.php
index e90dcf6..a6b315c 100644
--- a/core/lib/Drupal/Core/Form/FormBase.php
+++ b/core/lib/Drupal/Core/Form/FormBase.php
@@ -47,6 +47,13 @@ abstract class FormBase implements FormInterface, ContainerInjectionInterface {
protected $configFactory;
/**
+ * The logger factory.
+ *
+ * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
+ */
+ protected $loggerFactory;
+
+ /**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
@@ -187,4 +194,20 @@ abstract class FormBase implements FormInterface, ContainerInjectionInterface {
return $this;
}
+ /**
+ * Gets the logger for a specific channel.
+ *
+ * @param string $channel
+ * The name of the channel.
+ *
+ * @return \Psr\Log\LoggerInterface
+ * The logger for this channel.
+ */
+ protected function logger($channel) {
+ if (!$this->loggerFactory) {
+ $this->loggerFactory = $this->container()->get('logger.factory');
+ }
+ return $this->loggerFactory->get($channel);
+ }
+
}
diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php
index b3ae30d..1a5c19b 100644
--- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php
+++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php
@@ -10,6 +10,7 @@ namespace Drupal\Core\ImageToolkit;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Image\ImageInterface;
use Drupal\Core\Plugin\PluginBase;
+use Psr\Log\LoggerInterface;
abstract class ImageToolkitBase extends PluginBase implements ImageToolkitInterface {
@@ -28,6 +29,14 @@ abstract class ImageToolkitBase extends PluginBase implements ImageToolkitInterf
protected $operationManager;
/**
+ * A logger instance.
+ *
+ * @var \Psr\Log\LoggerInterface
+ */
+ protected $logger;
+
+
+ /**
* Constructs an ImageToolkitBase object.
*
* @param array $configuration
@@ -38,10 +47,13 @@ abstract class ImageToolkitBase extends PluginBase implements ImageToolkitInterf
* The plugin implementation definition.
* @param \Drupal\Core\ImageToolkit\ImageToolkitOperationManagerInterface $operation_manager
* The toolkit operation manager.
+ * @param \Psr\Log\LoggerInterface $logger
+ * A logger instance.
*/
- public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImageToolkitOperationManagerInterface $operation_manager) {
+ public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImageToolkitOperationManagerInterface $operation_manager, LoggerInterface $logger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->operationManager = $operation_manager;
+ $this->logger = $logger;
}
/**
@@ -90,11 +102,11 @@ abstract class ImageToolkitBase extends PluginBase implements ImageToolkitInterf
return $this->getToolkitOperation($operation)->apply($arguments);
}
catch (PluginNotFoundException $e) {
- \Drupal::logger('image')->error("The selected image handling toolkit '@toolkit' can not process operation '@operation'.", array('@toolkit' => $this->getPluginId(), '@operation' => $operation));
+ $this->logger->error("The selected image handling toolkit '@toolkit' can not process operation '@operation'.", array('@toolkit' => $this->getPluginId(), '@operation' => $operation));
return FALSE;
}
catch (\InvalidArgumentException $e) {
- \Drupal::logger('image')->warning($e->getMessage(), array());
+ $this->logger->warning($e->getMessage(), array());
return FALSE;
}
}
diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php
index 789ef5a..270f870 100644
--- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php
+++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php
@@ -12,6 +12,7 @@ use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Component\Plugin\Factory\DefaultFactory;
+use Psr\Log\LoggerInterface;
/**
* Manages toolkit plugins.
@@ -33,6 +34,13 @@ class ImageToolkitManager extends DefaultPluginManager {
protected $operationManager;
/**
+ * A logger instance.
+ *
+ * @var \Psr\Log\LoggerInterface
+ */
+ protected $logger;
+
+ /**
* Constructs the ImageToolkitManager object.
*
* @param \Traversable $namespaces
@@ -46,13 +54,16 @@ class ImageToolkitManager extends DefaultPluginManager {
* The module handler.
* @param \Drupal\Core\ImageToolkit\ImageToolkitOperationManagerInterface $operation_manager
* The toolkit operation manager.
+ * @param \Psr\Log\LoggerInterface $logger
+ * A logger instance.
*/
- public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ImageToolkitOperationManagerInterface $operation_manager) {
+ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ImageToolkitOperationManagerInterface $operation_manager, LoggerInterface $logger) {
parent::__construct('Plugin/ImageToolkit', $namespaces, $module_handler, 'Drupal\Core\ImageToolkit\Annotation\ImageToolkit');
$this->setCacheBackend($cache_backend, 'image_toolkit_plugins');
$this->configFactory = $config_factory;
$this->operationManager = $operation_manager;
+ $this->logger = $logger;
}
/**
@@ -115,7 +126,7 @@ class ImageToolkitManager extends DefaultPluginManager {
public function createInstance($plugin_id, array $configuration = array()) {
$plugin_definition = $this->getDefinition($plugin_id);
$plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition);
- return new $plugin_class($configuration, $plugin_id, $plugin_definition, $this->operationManager);
+ return new $plugin_class($configuration, $plugin_id, $plugin_definition, $this->operationManager, $this->logger);
}
}
diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php
index 6b66c29..eb13a9f 100644
--- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php
+++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php
@@ -10,6 +10,7 @@ namespace Drupal\Core\ImageToolkit;
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\Component\Utility\String;
use Drupal\Core\Plugin\PluginBase;
+use Psr\Log\LoggerInterface;
abstract class ImageToolkitOperationBase extends PluginBase implements ImageToolkitOperationInterface {
@@ -21,6 +22,13 @@ abstract class ImageToolkitOperationBase extends PluginBase implements ImageTool
protected $toolkit;
/**
+ * A logger instance.
+ *
+ * @var \Psr\Log\LoggerInterface
+ */
+ protected $logger;
+
+ /**
* Constructs an image toolkit operation plugin.
*
* @param array $configuration
@@ -31,10 +39,13 @@ abstract class ImageToolkitOperationBase extends PluginBase implements ImageTool
* The plugin implementation definition.
* @param \Drupal\Core\ImageToolkit\ImageToolkitInterface $toolkit
* The image toolkit.
+ * @param \Psr\Log\LoggerInterface $logger
+ * A logger instance.
*/
- public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImageToolkitInterface $toolkit) {
+ public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImageToolkitInterface $toolkit, LoggerInterface $logger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->toolkit = $toolkit;
+ $this->logger = $logger;
}
/**
diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php
index a18678b..20ecc55 100644
--- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php
+++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php
@@ -13,6 +13,7 @@ use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Component\Utility\String;
+use Psr\Log\LoggerInterface;
/**
* Manages toolkit operation plugins.
@@ -20,6 +21,13 @@ use Drupal\Component\Utility\String;
class ImageToolkitOperationManager extends DefaultPluginManager implements ImageToolkitOperationManagerInterface {
/**
+ * A logger instance.
+ *
+ * @var \Psr\Log\LoggerInterface
+ */
+ protected $logger;
+
+ /**
* Constructs the ImageToolkitOperationManager object.
*
* @param \Traversable $namespaces
@@ -29,12 +37,15 @@ class ImageToolkitOperationManager extends DefaultPluginManager implements Image
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to invoke the alter hook with.
+ * @param \Psr\Log\LoggerInterface $logger
+ * A logger instance.
*/
- public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
+ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LoggerInterface $logger) {
parent::__construct('Plugin/ImageToolkit/Operation', $namespaces, $module_handler, 'Drupal\Core\ImageToolkit\Annotation\ImageToolkitOperation');
$this->alterInfo('image_toolkit_operation');
$this->setCacheBackend($cache_backend, 'image_toolkit_operation_plugins');
+ $this->logger = $logger;
}
/**
@@ -79,7 +90,7 @@ class ImageToolkitOperationManager extends DefaultPluginManager implements Image
public function createInstance($plugin_id, array $configuration = array(), ImageToolkitInterface $toolkit = NULL) {
$plugin_definition = $this->getDefinition($plugin_id);
$plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition);
- return new $plugin_class($configuration, $plugin_id, $plugin_definition, $toolkit);
+ return new $plugin_class($configuration, $plugin_id, $plugin_definition, $toolkit, $this->logger);
}
/**
diff --git a/core/modules/action/src/Form/ActionDeleteForm.php b/core/modules/action/src/Form/ActionDeleteForm.php
index a65d574..95b8ebb 100644
--- a/core/modules/action/src/Form/ActionDeleteForm.php
+++ b/core/modules/action/src/Form/ActionDeleteForm.php
@@ -43,7 +43,7 @@ class ActionDeleteForm extends EntityConfirmFormBase {
public function submit(array $form, FormStateInterface $form_state) {
$this->entity->delete();
- watchdog('user', 'Deleted action %aid (%action)', array('%aid' => $this->entity->id(), '%action' => $this->entity->label()));
+ $this->logger('user')->notice('Deleted action %aid (%action)', array('%aid' => $this->entity->id(), '%action' => $this->entity->label()));
drupal_set_message($this->t('Action %action was deleted', array('%action' => $this->entity->label())));
$form_state['redirect_route'] = $this->getCancelUrl();
diff --git a/core/modules/action/src/Plugin/Action/EmailAction.php b/core/modules/action/src/Plugin/Action/EmailAction.php
index a9a00a9..b973204 100644
--- a/core/modules/action/src/Plugin/Action/EmailAction.php
+++ b/core/modules/action/src/Plugin/Action/EmailAction.php
@@ -12,6 +12,7 @@ use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Utility\Token;
+use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@@ -40,6 +41,13 @@ class EmailAction extends ConfigurableActionBase implements ContainerFactoryPlug
protected $storage;
/**
+ * A logger instance.
+ *
+ * @var \Psr\Log\LoggerInterface
+ */
+ protected $logger;
+
+ /**
* Constructs a EmailAction object.
*
* @param array $configuration
@@ -52,12 +60,15 @@ class EmailAction extends ConfigurableActionBase implements ContainerFactoryPlug
* The token service.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
+ * @param \Psr\Log\LoggerInterface $logger
+ * A logger instance.
*/
- public function __construct(array $configuration, $plugin_id, $plugin_definition, Token $token, EntityManagerInterface $entity_manager) {
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, Token $token, EntityManagerInterface $entity_manager, LoggerInterface $logger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->token = $token;
$this->storage = $entity_manager->getStorage('user');
+ $this->logger = $logger;
}
/**
@@ -66,7 +77,8 @@ class EmailAction extends ConfigurableActionBase implements ContainerFactoryPlug
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition,
$container->get('token'),
- $container->get('entity.manager')
+ $container->get('entity.manager'),
+ $container->get('logger.factory')->get('action')
);
}
@@ -94,10 +106,10 @@ class EmailAction extends ConfigurableActionBase implements ContainerFactoryPlug
$params = array('context' => $this->configuration);
if (drupal_mail('system', 'action_send_email', $recipient, $langcode, $params)) {
- watchdog('action', 'Sent email to %recipient', array('%recipient' => $recipient));
+ $this->logger->notice('Sent email to %recipient', array('%recipient' => $recipient));
}
else {
- watchdog('error', 'Unable to send email to %recipient', array('%recipient' => $recipient));
+ $this->logger->error('Unable to send email to %recipient', array('%recipient' => $recipient));
}
}
diff --git a/core/modules/aggregator/src/FeedForm.php b/core/modules/aggregator/src/FeedForm.php
index 6d9d3ea..12e7c6e 100644
--- a/core/modules/aggregator/src/FeedForm.php
+++ b/core/modules/aggregator/src/FeedForm.php
@@ -70,7 +70,7 @@ class FeedForm extends ContentEntityForm {
$form_state['redirect_route'] = $feed->urlInfo('canonical');
}
else {
- watchdog('aggregator', 'Feed %feed added.', array('%feed' => $feed->label()), WATCHDOG_NOTICE, l($this->t('View'), 'admin/config/services/aggregator'));
+ $this->logger('aggregator')->notice('Feed %feed added.', array('%feed' => $feed->label(), 'link' => l($this->t('View'), 'admin/config/services/aggregator')));
drupal_set_message($this->t('The feed %feed has been added.', array('%feed' => $feed->label())));
}
}
diff --git a/core/modules/aggregator/src/Form/FeedDeleteForm.php b/core/modules/aggregator/src/Form/FeedDeleteForm.php
index 83c171e..6786544 100644
--- a/core/modules/aggregator/src/Form/FeedDeleteForm.php
+++ b/core/modules/aggregator/src/Form/FeedDeleteForm.php
@@ -42,7 +42,7 @@ class FeedDeleteForm extends ContentEntityConfirmFormBase {
*/
public function submit(array $form, FormStateInterface $form_state) {
$this->entity->delete();
- watchdog('aggregator', 'Feed %feed deleted.', array('%feed' => $this->entity->label()));
+ $this->logger('aggregator')->notice('Feed %feed deleted.', array('%feed' => $this->entity->label()));
drupal_set_message($this->t('The feed %feed has been deleted.', array('%feed' => $this->entity->label())));
$form_state['redirect_route'] = new Url('aggregator.sources');
}
diff --git a/core/modules/aggregator/src/Form/OpmlFeedAdd.php b/core/modules/aggregator/src/Form/OpmlFeedAdd.php
index 3bed94f..6dc0fdb 100644
--- a/core/modules/aggregator/src/Form/OpmlFeedAdd.php
+++ b/core/modules/aggregator/src/Form/OpmlFeedAdd.php
@@ -125,7 +125,7 @@ class OpmlFeedAdd extends FormBase {
$data = $response->getBody(TRUE);
}
catch (RequestException $e) {
- watchdog('aggregator', 'Failed to download OPML file due to "%error".', array('%error' => $e->getMessage()), WATCHDOG_WARNING);
+ $this->logger('aggregator')->warning('Failed to download OPML file due to "%error".', array('%error' => $e->getMessage()));
drupal_set_message($this->t('Failed to download OPML file due to "%error".', array('%error' => $e->getMessage())));
return;
}
diff --git a/core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php b/core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php
index ce36696..8695d25 100644
--- a/core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php
+++ b/core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php
@@ -13,6 +13,7 @@ use Drupal\Component\Datetime\DateTimePlus;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
+use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@@ -36,13 +37,23 @@ class DefaultFetcher implements FetcherInterface, ContainerFactoryPluginInterfac
protected $httpClient;
/**
+ * A logger instance.
+ *
+ * @var \Psr\Log\LoggerInterface
+ */
+ protected $logger;
+
+ /**
* Constructs a DefaultFetcher object.
*
* @param \GuzzleHttp\ClientInterface $http_client
* A Guzzle client object.
+ * @param \Psr\Log\LoggerInterface $logger
+ * A logger instance.
*/
- public function __construct(ClientInterface $http_client) {
+ public function __construct(ClientInterface $http_client, LoggerInterface $logger) {
$this->httpClient = $http_client;
+ $this->logger = $logger;
}
/**
@@ -50,7 +61,8 @@ class DefaultFetcher implements FetcherInterface, ContainerFactoryPluginInterfac
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
- $container->get('http_client')
+ $container->get('http_client'),
+ $container->get('logger.factory')->get('aggregator')
);
}
@@ -91,7 +103,7 @@ class DefaultFetcher implements FetcherInterface, ContainerFactoryPluginInterfac
return TRUE;
}
catch (RequestException $e) {
- watchdog('aggregator', 'The feed from %site seems to be broken because of error "%error".', array('%site' => $feed->label(), '%error' => $e->getMessage()), WATCHDOG_WARNING);
+ $this->logger->warning('The feed from %site seems to be broken because of error "%error".', array('%site' => $feed->label(), '%error' => $e->getMessage()));
drupal_set_message(t('The feed from %site seems to be broken because of error "%error".', array('%site' => $feed->label(), '%error' => $e->getMessage())) , 'warning');
return FALSE;
}
diff --git a/core/modules/ban/src/Form/BanDelete.php b/core/modules/ban/src/Form/BanDelete.php
index b607ba9..2734540 100644
--- a/core/modules/ban/src/Form/BanDelete.php
+++ b/core/modules/ban/src/Form/BanDelete.php
@@ -91,7 +91,7 @@ class BanDelete extends ConfirmFormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->ipManager->unbanIp($this->banIp);
- watchdog('user', 'Deleted %ip', array('%ip' => $this->banIp));
+ $this->logger('user')->notice('Deleted %ip', array('%ip' => $this->banIp));
drupal_set_message($this->t('The IP address %ip was deleted.', array('%ip' => $this->banIp)));
$form_state['redirect_route'] = $this->getCancelUrl();
}
diff --git a/core/modules/block_content/src/BlockContentForm.php b/core/modules/block_content/src/BlockContentForm.php
index 1524f42..86ffc0c 100644
--- a/core/modules/block_content/src/BlockContentForm.php
+++ b/core/modules/block_content/src/BlockContentForm.php
@@ -194,16 +194,17 @@ class BlockContentForm extends ContentEntityForm {
$block = $this->entity;
$insert = $block->isNew();
$block->save();
- $watchdog_args = array('@type' => $block->bundle(), '%info' => $block->label());
+ $context = array('@type' => $block->bundle(), '%info' => $block->label());
+ $logger = $this->logger('block_content');
$block_type = entity_load('block_content_type', $block->bundle());
$t_args = array('@type' => $block_type->label(), '%info' => $block->label());
if ($insert) {
- watchdog('content', '@type: added %info.', $watchdog_args, WATCHDOG_NOTICE);
+ $logger->notice('@type: added %info.', $context);
drupal_set_message($this->t('@type %info has been created.', $t_args));
}
else {
- watchdog('content', '@type: updated %info.', $watchdog_args, WATCHDOG_NOTICE);
+ $logger->notice('@type: updated %info.', $context);
drupal_set_message($this->t('@type %info has been updated.', $t_args));
}
diff --git a/core/modules/block_content/src/BlockContentTypeForm.php b/core/modules/block_content/src/BlockContentTypeForm.php
index 025d673..93c86a3 100644
--- a/core/modules/block_content/src/BlockContentTypeForm.php
+++ b/core/modules/block_content/src/BlockContentTypeForm.php
@@ -93,13 +93,14 @@ class BlockContentTypeForm extends EntityForm {
$status = $block_type->save();
$edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo());
+ $logger = $this->logger('block_content');
if ($status == SAVED_UPDATED) {
drupal_set_message(t('Custom block type %label has been updated.', array('%label' => $block_type->label())));
- watchdog('block_content', 'Custom block type %label has been updated.', array('%label' => $block_type->label()), WATCHDOG_NOTICE, $edit_link);
+ $logger->notice('Custom block type %label has been updated.', array('%label' => $block_type->label(), 'link' => $edit_link));
}
else {
drupal_set_message(t('Custom block type %label has been added.', array('%label' => $block_type->label())));
- watchdog('block_content', 'Custom block type %label has been added.', array('%label' => $block_type->label()), WATCHDOG_NOTICE, $edit_link);
+ $logger->notice('Custom block type %label has been added.', array('%label' => $block_type->label(), 'link' => $edit_link));
}
$form_state['redirect_route']['route_name'] = 'block_content.type_list';
diff --git a/core/modules/block_content/src/Form/BlockContentDeleteForm.php b/core/modules/block_content/src/Form/BlockContentDeleteForm.php
index 88249ae..1fbb99a 100644
--- a/core/modules/block_content/src/Form/BlockContentDeleteForm.php
+++ b/core/modules/block_content/src/Form/BlockContentDeleteForm.php
@@ -57,7 +57,7 @@ class BlockContentDeleteForm extends ContentEntityConfirmFormBase {
public function submit(array $form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message($this->t('Custom block %label has been deleted.', array('%label' => $this->entity->label())));
- watchdog('block_content', 'Custom block %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE);
+ $this->logger('block_content')->notice('Custom block %label has been deleted.', array('%label' => $this->entity->label()));
$form_state['redirect_route'] = new Url('block_content.list');
}
diff --git a/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php b/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php
index decda49..b7c99a6 100644
--- a/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php
+++ b/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php
@@ -86,7 +86,7 @@ class BlockContentTypeDeleteForm extends EntityConfirmFormBase {
public function submit(array $form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message(t('Custom block type %label has been deleted.', array('%label' => $this->entity->label())));
- watchdog('block_content', 'Custom block type %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE);
+ $this->logger('block_content')->notice('Custom block type %label has been deleted.', array('%label' => $this->entity->label()));
$form_state['redirect_route'] = $this->getCancelUrl();
}
diff --git a/core/modules/book/src/Form/BookAdminEditForm.php b/core/modules/book/src/Form/BookAdminEditForm.php
index 9a342f0..39d6e0d 100644
--- a/core/modules/book/src/Form/BookAdminEditForm.php
+++ b/core/modules/book/src/Form/BookAdminEditForm.php
@@ -120,7 +120,7 @@ class BookAdminEditForm extends FormBase {
$node->book['link_title'] = $values['title'];
$node->setNewRevision();
$node->save();
- watchdog('content', 'book: updated %title.', array('%title' => $node->label()), WATCHDOG_NOTICE, l($this->t('View'), 'node/' . $node->id()));
+ $this->logger('content')->notice('book: updated %title.', array('%title' => $node->label(), 'link' => l($this->t('View'), 'node/' . $node->id())));
}
}
}
diff --git a/core/modules/comment/src/CommentForm.php b/core/modules/comment/src/CommentForm.php
index 9701e49..343d93a 100644
--- a/core/modules/comment/src/CommentForm.php
+++ b/core/modules/comment/src/CommentForm.php
@@ -364,6 +364,7 @@ class CommentForm extends ContentEntityForm {
$entity = $comment->getCommentedEntity();
$field_name = $comment->getFieldName();
$uri = $entity->urlInfo();
+ $logger = $this->logger('content');
if ($this->currentUser->hasPermission('post comments') && ($this->currentUser->hasPermission('administer comments') || $entity->{$field_name}->status == CommentItemInterface::OPEN)) {
// Save the anonymous user information to a cookie for reuse.
@@ -374,8 +375,8 @@ class CommentForm extends ContentEntityForm {
$comment->save();
$form_state['values']['cid'] = $comment->id();
- // Add an entry to the watchdog log.
- watchdog('content', 'Comment posted: %subject.', array('%subject' => $comment->getSubject()), WATCHDOG_NOTICE, l(t('View'), 'comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id())));
+ // Add a log entry.
+ $logger->notice('Comment posted: %subject.', array('%subject' => $comment->getSubject(), 'link' => l(t('View'), 'comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id()))));
// Explain the approval queue if necessary.
if (!$comment->isPublished()) {
@@ -398,7 +399,7 @@ class CommentForm extends ContentEntityForm {
$uri->setOption('fragment', 'comment-' . $comment->id());
}
else {
- watchdog('content', 'Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->getSubject()), WATCHDOG_WARNING);
+ $logger->warning('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->getSubject()));
drupal_set_message($this->t('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->getSubject())), 'error');
// Redirect the user to the entity they are commenting on.
}
diff --git a/core/modules/comment/src/Form/ConfirmDeleteMultiple.php b/core/modules/comment/src/Form/ConfirmDeleteMultiple.php
index 39fe538..fa3494c 100644
--- a/core/modules/comment/src/Form/ConfirmDeleteMultiple.php
+++ b/core/modules/comment/src/Form/ConfirmDeleteMultiple.php
@@ -121,7 +121,7 @@ class ConfirmDeleteMultiple extends ConfirmFormBase {
if ($form_state['values']['confirm']) {
$this->commentStorage->delete($this->comments);
$count = count($form_state['values']['comments']);
- watchdog('content', 'Deleted @count comments.', array('@count' => $count));
+ $this->logger('content')->notice('Deleted @count comments.', array('@count' => $count));
drupal_set_message(format_plural($count, 'Deleted 1 comment.', 'Deleted @count comments.'));
}
$form_state['redirect_route'] = $this->getCancelUrl();
diff --git a/core/modules/comment/src/Form/DeleteForm.php b/core/modules/comment/src/Form/DeleteForm.php
index 1ee7b4c..a6d01e8 100644
--- a/core/modules/comment/src/Form/DeleteForm.php
+++ b/core/modules/comment/src/Form/DeleteForm.php
@@ -51,7 +51,7 @@ class DeleteForm extends ContentEntityConfirmFormBase {
// Delete the comment and its replies.
$this->entity->delete();
drupal_set_message($this->t('The comment and all its replies have been deleted.'));
- watchdog('content', 'Deleted comment @cid and its replies.', array('@cid' => $this->entity->id()));
+ $this->logger('content')->notice('Deleted comment @cid and its replies.', array('@cid' => $this->entity->id()));
$form_state['redirect_route'] = $this->getCancelUrl();
}
diff --git a/core/modules/contact/src/CategoryForm.php b/core/modules/contact/src/CategoryForm.php
index df91084..0b697d1 100644
--- a/core/modules/contact/src/CategoryForm.php
+++ b/core/modules/contact/src/CategoryForm.php
@@ -100,11 +100,11 @@ class CategoryForm extends EntityForm {
if ($status == SAVED_UPDATED) {
drupal_set_message($this->t('Category %label has been updated.', array('%label' => $category->label())));
- watchdog('contact', 'Category %label has been updated.', array('%label' => $category->label()), WATCHDOG_NOTICE, $edit_link);
+ $this->logger('contact')->notice('Category %label has been updated.', array('%label' => $category->label(), 'link' => $edit_link));
}
else {
drupal_set_message($this->t('Category %label has been added.', array('%label' => $category->label())));
- watchdog('contact', 'Category %label has been added.', array('%label' => $category->label()), WATCHDOG_NOTICE, $edit_link);
+ $this->logger('contact')->notice('Category %label has been added.', array('%label' => $category->label(), 'link' => $edit_link));
}
// Update the default category.
diff --git a/core/modules/contact/src/Form/CategoryDeleteForm.php b/core/modules/contact/src/Form/CategoryDeleteForm.php
index 5fddb08..aca9161 100644
--- a/core/modules/contact/src/Form/CategoryDeleteForm.php
+++ b/core/modules/contact/src/Form/CategoryDeleteForm.php
@@ -43,7 +43,7 @@ class CategoryDeleteForm extends EntityConfirmFormBase {
public function submit(array $form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message($this->t('Category %label has been deleted.', array('%label' => $this->entity->label())));
- watchdog('contact', 'Category %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE);
+ $this->logger('contact')->notice('Category %label has been deleted.', array('%label' => $this->entity->label()));
$form_state['redirect_route'] = $this->getCancelUrl();
}
diff --git a/core/modules/contact/src/MessageForm.php b/core/modules/contact/src/MessageForm.php
index 30ac410..69c804a 100644
--- a/core/modules/contact/src/MessageForm.php
+++ b/core/modules/contact/src/MessageForm.php
@@ -239,14 +239,14 @@ class MessageForm extends ContentEntityForm {
$this->flood->register('contact', $this->config('contact.settings')->get('flood.interval'));
if (!$message->isPersonal()) {
- watchdog('contact', '%sender-name (@sender-from) sent an email regarding %category.', array(
+ $this->logger('contact')->notice('%sender-name (@sender-from) sent an email regarding %category.', array(
'%sender-name' => $sender->getUsername(),
'@sender-from' => $sender->getEmail(),
'%category' => $category->label(),
));
}
else {
- watchdog('contact', '%sender-name (@sender-from) sent %recipient-name an email.', array(
+ $this->logger('contact')->notice('%sender-name (@sender-from) sent %recipient-name an email.', array(
'%sender-name' => $sender->getUsername(),
'@sender-from' => $sender->getEmail(),
'%recipient-name' => $message->getPersonalRecipient()->getUsername(),
diff --git a/core/modules/filter/src/Plugin/Filter/FilterNull.php b/core/modules/filter/src/Plugin/Filter/FilterNull.php
index 9c30edc..3b2d943 100644
--- a/core/modules/filter/src/Plugin/Filter/FilterNull.php
+++ b/core/modules/filter/src/Plugin/Filter/FilterNull.php
@@ -40,7 +40,7 @@ class FilterNull extends FilterBase {
// Once per filter, log that a filter plugin was missing.
if (!$this->logged) {
$this->logged = TRUE;
- watchdog('filter', 'Missing filter plugin: %filter.', array('%filter' => $plugin_id), WATCHDOG_ALERT);
+ \Drupal::logger('filter')->alert('Missing filter plugin: %filter.', array('%filter' => $plugin_id));
}
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
diff --git a/core/modules/forum/src/Form/DeleteForm.php b/core/modules/forum/src/Form/DeleteForm.php
index 94cdf11..ddde478 100644
--- a/core/modules/forum/src/Form/DeleteForm.php
+++ b/core/modules/forum/src/Form/DeleteForm.php
@@ -67,7 +67,7 @@ class DeleteForm extends ConfirmFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->taxonomyTerm->delete();
drupal_set_message($this->t('The forum %label and all sub-forums have been deleted.', array('%label' => $this->taxonomyTerm->label())));
- watchdog('forum', 'forum: deleted %label and all its sub-forums.', array('%label' => $this->taxonomyTerm->label()), WATCHDOG_NOTICE);
+ $this->logger('forum')->notice('forum: deleted %label and all its sub-forums.', array('%label' => $this->taxonomyTerm->label()));
$form_state['redirect_route'] = $this->getCancelUrl();
}
diff --git a/core/modules/forum/src/Form/ForumForm.php b/core/modules/forum/src/Form/ForumForm.php
index 3007380..4290452 100644
--- a/core/modules/forum/src/Form/ForumForm.php
+++ b/core/modules/forum/src/Form/ForumForm.php
@@ -82,13 +82,13 @@ class ForumForm extends TermForm {
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created new @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType)));
- watchdog('forum', 'Created new @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType), WATCHDOG_NOTICE, l($this->t('Edit'), 'admin/structure/forum/edit/' . $this->urlStub . '/' . $term->id()));
+ $this->logger('forum')->notice('Created new @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType, 'link' => l($this->t('Edit'), 'admin/structure/forum/edit/' . $this->urlStub . '/' . $term->id())));
$form_state['values']['tid'] = $term->id();
break;
case SAVED_UPDATED:
drupal_set_message($this->t('The @type %term has been updated.', array('%term' => $term->getName(), '@type' => $this->forumFormType)));
- watchdog('taxonomy', 'Updated @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType), WATCHDOG_NOTICE, l($this->t('Edit'), 'admin/structure/forum/edit/' . $this->urlStub . '/' . $term->id()));
+ $this->logger('forum')->notice('Updated @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType, 'link' => l($this->t('Edit'), 'admin/structure/forum/edit/' . $this->urlStub . '/' . $term->id())));
break;
}
diff --git a/core/modules/image/src/Controller/ImageStyleDownloadController.php b/core/modules/image/src/Controller/ImageStyleDownloadController.php
index bf4f9d9..3e4bcf0 100644
--- a/core/modules/image/src/Controller/ImageStyleDownloadController.php
+++ b/core/modules/image/src/Controller/ImageStyleDownloadController.php
@@ -12,6 +12,7 @@ use Drupal\Core\Image\ImageFactory;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\image\ImageStyleInterface;
use Drupal\system\FileDownloadController;
+use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
@@ -39,16 +40,26 @@ class ImageStyleDownloadController extends FileDownloadController {
protected $imageFactory;
/**
+ * A logger instance.
+ *
+ * @var \Psr\Log\LoggerInterface
+ */
+ protected $logger;
+
+ /**
* Constructs a ImageStyleDownloadController object.
*
* @param \Drupal\Core\Lock\LockBackendInterface $lock
* 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) {
+ public function __construct(LockBackendInterface $lock, ImageFactory $image_factory, LoggerInterface $logger) {
$this->lock = $lock;
$this->imageFactory = $image_factory;
+ $this->logger = $logger;
}
/**
@@ -57,7 +68,8 @@ class ImageStyleDownloadController extends FileDownloadController {
public static function create(ContainerInterface $container) {
return new static(
$container->get('lock'),
- $container->get('image.factory')
+ $container->get('image.factory'),
+ $container->get('logger.factory')->get('image')
);
}
@@ -118,7 +130,7 @@ class ImageStyleDownloadController extends FileDownloadController {
// Don't try to generate file if source is missing.
if (!file_exists($image_uri)) {
- watchdog('image', 'Source image at %source_image_path not found while trying to generate derivative image at %derivative_path.', array('%source_image_path' => $image_uri, '%derivative_path' => $derivative_uri));
+ $this->logger->notice('Source image at %source_image_path not found while trying to generate derivative image at %derivative_path.', array('%source_image_path' => $image_uri, '%derivative_path' => $derivative_uri));
return new Response($this->t('Error generating image, missing source file.'), 404);
}
@@ -153,7 +165,7 @@ class ImageStyleDownloadController extends FileDownloadController {
return new BinaryFileResponse($uri, 200, $headers);
}
else {
- watchdog('image', 'Unable to generate the derived image located at %path.', array('%path' => $derivative_uri));
+ $this->logger->notice('Unable to generate the derived image located at %path.', array('%path' => $derivative_uri));
return new Response($this->t('Error generating image.'), 500);
}
}
diff --git a/core/modules/image/src/Entity/ImageStyle.php b/core/modules/image/src/Entity/ImageStyle.php
index 10cd626..a122aa4 100644
--- a/core/modules/image/src/Entity/ImageStyle.php
+++ b/core/modules/image/src/Entity/ImageStyle.php
@@ -272,7 +272,7 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
// Build the destination folder tree if it doesn't already exist.
if (!file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
- watchdog('image', 'Failed to create style directory: %directory', array('%directory' => $directory), WATCHDOG_ERROR);
+ \Drupal::logger('image')->error('Failed to create style directory: %directory', array('%directory' => $directory));
return FALSE;
}
@@ -287,7 +287,7 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
if (!$image->save($derivative_uri)) {
if (file_exists($derivative_uri)) {
- watchdog('image', 'Cached image file %destination already exists. There may be an issue with your rewrite configuration.', array('%destination' => $derivative_uri), WATCHDOG_ERROR);
+ \Drupal::logger('image')->error('Cached image file %destination already exists. There may be an issue with your rewrite configuration.', array('%destination' => $derivative_uri));
}
return FALSE;
}
diff --git a/core/modules/image/src/ImageEffectBase.php b/core/modules/image/src/ImageEffectBase.php
index 91bdc29..dac7966 100644
--- a/core/modules/image/src/ImageEffectBase.php
+++ b/core/modules/image/src/ImageEffectBase.php
@@ -7,12 +7,15 @@
namespace Drupal\image;
+use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
+use Psr\Log\LoggerInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a base class for image effects.
*/
-abstract class ImageEffectBase extends PluginBase implements ImageEffectInterface {
+abstract class ImageEffectBase extends PluginBase implements ImageEffectInterface, ContainerFactoryPluginInterface {
/**
* The image effect ID.
@@ -29,12 +32,32 @@ abstract class ImageEffectBase extends PluginBase implements ImageEffectInterfac
protected $weight = '';
/**
+ * A logger instance.
+ *
+ * @var \Psr\Log\LoggerInterface
+ */
+ protected $logger;
+
+ /**
* {@inheritdoc}
*/
- public function __construct(array $configuration, $plugin_id, $plugin_definition) {
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->setConfiguration($configuration);
+ $this->logger = $logger;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
+ return new static(
+ $configuration,
+ $plugin_id,
+ $plugin_definition,
+ $container->get('logger.factory')->get('image')
+ );
}
/**
diff --git a/core/modules/image/src/Plugin/ImageEffect/CropImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/CropImageEffect.php
index 0edac98..8522b9e 100644
--- a/core/modules/image/src/Plugin/ImageEffect/CropImageEffect.php
+++ b/core/modules/image/src/Plugin/ImageEffect/CropImageEffect.php
@@ -29,7 +29,7 @@ class CropImageEffect extends ResizeImageEffect {
$x = image_filter_keyword($x, $image->getWidth(), $this->configuration['width']);
$y = image_filter_keyword($y, $image->getHeight(), $this->configuration['height']);
if (!$image->crop($x, $y, $this->configuration['width'], $this->configuration['height'])) {
- watchdog('image', 'Image crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR);
+ $this->logger->error('Image crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()));
return FALSE;
}
return TRUE;
diff --git a/core/modules/image/src/Plugin/ImageEffect/DesaturateImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/DesaturateImageEffect.php
index 4d899c6..97d31d8 100644
--- a/core/modules/image/src/Plugin/ImageEffect/DesaturateImageEffect.php
+++ b/core/modules/image/src/Plugin/ImageEffect/DesaturateImageEffect.php
@@ -32,7 +32,7 @@ class DesaturateImageEffect extends ImageEffectBase {
*/
public function applyEffect(ImageInterface $image) {
if (!$image->desaturate()) {
- watchdog('image', 'Image desaturate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR);
+ $this->logger->error('Image desaturate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()));
return FALSE;
}
return TRUE;
diff --git a/core/modules/image/src/Plugin/ImageEffect/ResizeImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/ResizeImageEffect.php
index 15f0080..1edf23c 100644
--- a/core/modules/image/src/Plugin/ImageEffect/ResizeImageEffect.php
+++ b/core/modules/image/src/Plugin/ImageEffect/ResizeImageEffect.php
@@ -27,7 +27,7 @@ class ResizeImageEffect extends ConfigurableImageEffectBase {
*/
public function applyEffect(ImageInterface $image) {
if (!$image->resize($this->configuration['width'], $this->configuration['height'])) {
- watchdog('image', 'Image resize failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR);
+ $this->logger->error('Image resize failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()));
return FALSE;
}
return TRUE;
diff --git a/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php
index 7f29aaf..eaaa860 100644
--- a/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php
+++ b/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php
@@ -47,7 +47,7 @@ class RotateImageEffect extends ConfigurableImageEffectBase {
}
if (!$image->rotate($this->configuration['degrees'], $this->configuration['bgcolor'])) {
- watchdog('image', 'Image rotate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR);
+ $this->logger->error('Image rotate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()));
return FALSE;
}
return TRUE;
diff --git a/core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php
index 7fed9b1..ca9479f 100644
--- a/core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php
+++ b/core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php
@@ -25,7 +25,7 @@ class ScaleAndCropImageEffect extends ResizeImageEffect {
*/
public function applyEffect(ImageInterface $image) {
if (!$image->scaleAndCrop($this->configuration['width'], $this->configuration['height'])) {
- watchdog('image', 'Image scale and crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR);
+ $this->logger->error('Image scale and crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()));
return FALSE;
}
return TRUE;
diff --git a/core/modules/image/src/Plugin/ImageEffect/ScaleImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/ScaleImageEffect.php
index a5dae9a..a6e1d23 100644
--- a/core/modules/image/src/Plugin/ImageEffect/ScaleImageEffect.php
+++ b/core/modules/image/src/Plugin/ImageEffect/ScaleImageEffect.php
@@ -27,7 +27,7 @@ class ScaleImageEffect extends ResizeImageEffect {
*/
public function applyEffect(ImageInterface $image) {
if (!$image->scale($this->configuration['width'], $this->configuration['height'], $this->configuration['upscale'])) {
- watchdog('image', 'Image scale failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR);
+ $this->logger->error('Image scale failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()));
return FALSE;
}
return TRUE;
diff --git a/core/modules/locale/src/Form/TranslateEditForm.php b/core/modules/locale/src/Form/TranslateEditForm.php
index 6c582d3..bb1939d 100644
--- a/core/modules/locale/src/Form/TranslateEditForm.php
+++ b/core/modules/locale/src/Form/TranslateEditForm.php
@@ -166,7 +166,7 @@ class TranslateEditForm extends TranslateFormBase {
if (!locale_string_is_safe($value)) {
$this->setFormError("strings][$lid][translations][$key", $form_state, $this->t('The submitted string contains disallowed HTML: %string', array('%string' => $value)));
$this->setFormError("translations][$langcode][$key", $form_state, $this->t('The submitted string contains disallowed HTML: %string', array('%string' => $value)));
- watchdog('locale', 'Attempted submission of a translation string with disallowed HTML: %string', array('%string' => $value), WATCHDOG_WARNING);
+ $this->logger('locale')->warning('Attempted submission of a translation string with disallowed HTML: %string', array('%string' => $value));
}
}
}
diff --git a/core/modules/menu_ui/src/Form/MenuDeleteForm.php b/core/modules/menu_ui/src/Form/MenuDeleteForm.php
index 2332b40..33712e4 100644
--- a/core/modules/menu_ui/src/Form/MenuDeleteForm.php
+++ b/core/modules/menu_ui/src/Form/MenuDeleteForm.php
@@ -117,6 +117,6 @@ class MenuDeleteForm extends EntityConfirmFormBase {
$t_args = array('%title' => $this->entity->label());
drupal_set_message(t('The custom menu %title has been deleted.', $t_args));
- watchdog('menu', 'Deleted custom menu %title and all its menu links.', $t_args, WATCHDOG_NOTICE);
+ $this->logger('menu')->notice('Deleted custom menu %title and all its menu links.', $t_args);
}
}
diff --git a/core/modules/menu_ui/src/MenuForm.php b/core/modules/menu_ui/src/MenuForm.php
index d115736..40123d5 100644
--- a/core/modules/menu_ui/src/MenuForm.php
+++ b/core/modules/menu_ui/src/MenuForm.php
@@ -185,11 +185,11 @@ class MenuForm extends EntityForm {
$edit_link = $this->linkGenerator->generateFromUrl($this->t('Edit'), $this->entity->urlInfo());
if ($status == SAVED_UPDATED) {
drupal_set_message($this->t('Menu %label has been updated.', array('%label' => $menu->label())));
- watchdog('menu', 'Menu %label has been updated.', array('%label' => $menu->label()), WATCHDOG_NOTICE, $edit_link);
+ $this->logger('menu')->notice('Menu %label has been updated.', array('%label' => $menu->label(), 'link' => $edit_link));
}
else {
drupal_set_message($this->t('Menu %label has been added.', array('%label' => $menu->label())));
- watchdog('menu', 'Menu %label has been added.', array('%label' => $menu->label()), WATCHDOG_NOTICE, $edit_link);
+ $this->logger('menu')->notice('Menu %label has been added.', array('%label' => $menu->label(), 'link' => $edit_link));
}
$form_state['redirect_route'] = $this->entity->urlInfo('edit-form');
diff --git a/core/modules/node/src/Form/DeleteMultiple.php b/core/modules/node/src/Form/DeleteMultiple.php
index a067ccb..4f0356e 100644
--- a/core/modules/node/src/Form/DeleteMultiple.php
+++ b/core/modules/node/src/Form/DeleteMultiple.php
@@ -121,7 +121,7 @@ class DeleteMultiple extends ConfirmFormBase {
$this->storage->delete($this->nodes);
$this->tempStoreFactory->get('node_multiple_delete_confirm')->delete(\Drupal::currentUser()->id());
$count = count($this->nodes);
- watchdog('content', 'Deleted @count posts.', array('@count' => $count));
+ $this->logger('content')->notice('Deleted @count posts.', array('@count' => $count));
drupal_set_message(format_plural($count, 'Deleted 1 post.', 'Deleted @count posts.'));
}
$form_state['redirect_route']['route_name'] = 'system.admin_content';
diff --git a/core/modules/node/src/Form/NodeDeleteForm.php b/core/modules/node/src/Form/NodeDeleteForm.php
index 19faa67..87df223 100644
--- a/core/modules/node/src/Form/NodeDeleteForm.php
+++ b/core/modules/node/src/Form/NodeDeleteForm.php
@@ -74,7 +74,7 @@ class NodeDeleteForm extends ContentEntityConfirmFormBase {
*/
public function submit(array $form, FormStateInterface $form_state) {
$this->entity->delete();
- watchdog('content', '@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label()));
+ $this->logger('content')->notice('@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label()));
$node_type_storage = $this->entityManager->getStorage('node_type');
$node_type = $node_type_storage->load($this->entity->bundle())->label();
drupal_set_message(t('@type %title has been deleted.', array('@type' => $node_type, '%title' => $this->entity->label())));
diff --git a/core/modules/node/src/Form/NodeRevisionDeleteForm.php b/core/modules/node/src/Form/NodeRevisionDeleteForm.php
index 0ab753d..4df7292 100644
--- a/core/modules/node/src/Form/NodeRevisionDeleteForm.php
+++ b/core/modules/node/src/Form/NodeRevisionDeleteForm.php
@@ -120,7 +120,7 @@ class NodeRevisionDeleteForm extends ConfirmFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->nodeStorage->deleteRevision($this->revision->getRevisionId());
- watchdog('content', '@type: deleted %title revision %revision.', array('@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()));
+ $this->logger('content')->notice('@type: deleted %title revision %revision.', array('@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()));
$node_type = $this->nodeTypeStorage->load($this->revision->bundle())->label();
drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($this->revision->getRevisionCreationTime()), '@type' => $node_type, '%title' => $this->revision->label())));
$form_state['redirect_route'] = array(
diff --git a/core/modules/node/src/Form/NodeRevisionRevertForm.php b/core/modules/node/src/Form/NodeRevisionRevertForm.php
index 147036f..c6dc728 100644
--- a/core/modules/node/src/Form/NodeRevisionRevertForm.php
+++ b/core/modules/node/src/Form/NodeRevisionRevertForm.php
@@ -113,7 +113,7 @@ class NodeRevisionRevertForm extends ConfirmFormBase {
$this->revision->save();
- watchdog('content', '@type: reverted %title revision %revision.', array('@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()));
+ $this->logger('content')->notice('@type: reverted %title revision %revision.', array('@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()));
drupal_set_message(t('@type %title has been reverted back to the revision from %revision-date.', array('@type' => node_get_type_label($this->revision), '%title' => $this->revision->label(), '%revision-date' => format_date($original_revision_timestamp))));
$form_state['redirect_route'] = array(
'route_name' => 'node.revision_overview',
diff --git a/core/modules/node/src/Form/NodeTypeDeleteConfirm.php b/core/modules/node/src/Form/NodeTypeDeleteConfirm.php
index 0c23ced..5cf4e2a 100644
--- a/core/modules/node/src/Form/NodeTypeDeleteConfirm.php
+++ b/core/modules/node/src/Form/NodeTypeDeleteConfirm.php
@@ -87,7 +87,7 @@ class NodeTypeDeleteConfirm extends EntityConfirmFormBase {
$this->entity->delete();
$t_args = array('%name' => $this->entity->label());
drupal_set_message(t('The content type %name has been deleted.', $t_args));
- watchdog('node', 'Deleted content type %name.', $t_args, WATCHDOG_NOTICE);
+ $this->logger('node')->notice('Deleted content type %name.', $t_args);
$form_state['redirect_route'] = $this->getCancelUrl();
}
diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php
index bf4b869..085cf2c 100644
--- a/core/modules/node/src/NodeForm.php
+++ b/core/modules/node/src/NodeForm.php
@@ -433,15 +433,15 @@ class NodeForm extends ContentEntityForm {
$insert = $node->isNew();
$node->save();
$node_link = l(t('View'), 'node/' . $node->id());
- $watchdog_args = array('@type' => $node->getType(), '%title' => $node->label());
+ $context = array('@type' => $node->getType(), '%title' => $node->label(), 'link' => $node_link);
$t_args = array('@type' => node_get_type_label($node), '%title' => $node->label());
if ($insert) {
- watchdog('content', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
+ $this->logger('content')->notice('@type: added %title.', $context);
drupal_set_message(t('@type %title has been created.', $t_args));
}
else {
- watchdog('content', '@type: updated %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
+ $this->logger('content')->notice('@type: updated %title.', $context);
drupal_set_message(t('@type %title has been updated.', $t_args));
}
diff --git a/core/modules/node/src/NodeTypeForm.php b/core/modules/node/src/NodeTypeForm.php
index f8cf927..9534e30 100644
--- a/core/modules/node/src/NodeTypeForm.php
+++ b/core/modules/node/src/NodeTypeForm.php
@@ -190,7 +190,8 @@ class NodeTypeForm extends EntityForm {
}
elseif ($status == SAVED_NEW) {
drupal_set_message(t('The content type %name has been added.', $t_args));
- watchdog('node', 'Added content type %name.', $t_args, WATCHDOG_NOTICE, l(t('View'), 'admin/structure/types'));
+ $context = array_merge($t_args, array('link' => l(t('View'), 'admin/structure/types')));
+ $this->logger('node')->notice('Added content type %name.', $context);
}
$form_state['redirect_route']['route_name'] = 'node.overview_types';
diff --git a/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php b/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php
index e614e0e..1d438b6 100644
--- a/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php
+++ b/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php
@@ -40,7 +40,7 @@ class ResponsiveImageMappingDeleteForm extends EntityConfirmFormBase {
public function submit(array $form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message($this->t('Responsive image mapping %label has been deleted.', array('%label' => $this->entity->label())));
- watchdog('responsive_image', 'Responsive image mapping %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE);
+ $this->logger('responsive_image')->notice('Responsive image mapping %label has been deleted.', array('%label' => $this->entity->label()));
$form_state['redirect_route'] = $this->getCancelUrl();
}
diff --git a/core/modules/responsive_image/src/ResponsiveImageMappingForm.php b/core/modules/responsive_image/src/ResponsiveImageMappingForm.php
index 7a38d12..de6ca92 100644
--- a/core/modules/responsive_image/src/ResponsiveImageMappingForm.php
+++ b/core/modules/responsive_image/src/ResponsiveImageMappingForm.php
@@ -125,7 +125,7 @@ class ResponsiveImageMappingForm extends EntityForm {
$responsive_image_mapping = $this->entity;
$responsive_image_mapping->save();
- watchdog('responsive_image', 'Responsive image mapping @label saved.', array('@label' => $responsive_image_mapping->label()), WATCHDOG_NOTICE);
+ $this->logger('responsive_image')->notice('Responsive image mapping @label saved.', array('@label' => $responsive_image_mapping->label()));
drupal_set_message($this->t('Responsive image mapping %label saved.', array('%label' => $responsive_image_mapping->label())));
// Redirect to edit form after creating a new mapping or after selecting
diff --git a/core/modules/rest/src/Plugin/ResourceBase.php b/core/modules/rest/src/Plugin/ResourceBase.php
index cab3b59..0cf3281 100644
--- a/core/modules/rest/src/Plugin/ResourceBase.php
+++ b/core/modules/rest/src/Plugin/ResourceBase.php
@@ -10,6 +10,7 @@ namespace Drupal\rest\Plugin;
use Drupal\Core\Access\AccessManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
+use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
@@ -34,6 +35,13 @@ abstract class ResourceBase extends PluginBase implements ContainerFactoryPlugin
protected $serializerFormats = array();
/**
+ * A logger instance.
+ *
+ * @var \Psr\Log\LoggerInterface
+ */
+ protected $logger;
+
+ /**
* Constructs a Drupal\rest\Plugin\ResourceBase object.
*
* @param array $configuration
@@ -44,10 +52,13 @@ abstract class ResourceBase extends PluginBase implements ContainerFactoryPlugin
* The plugin implementation definition.
* @param array $serializer_formats
* The available serialization formats.
+ * @param \Psr\Log\LoggerInterface $logger
+ * A logger instance.
*/
- public function __construct(array $configuration, $plugin_id, $plugin_definition, array $serializer_formats) {
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, array $serializer_formats, LoggerInterface $logger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->serializerFormats = $serializer_formats;
+ $this->logger = $logger;
}
/**
@@ -58,7 +69,8 @@ abstract class ResourceBase extends PluginBase implements ContainerFactoryPlugin
$configuration,
$plugin_id,
$plugin_definition,
- $container->getParameter('serializer.formats')
+ $container->getParameter('serializer.formats'),
+ $container->get('logger.factory')->get('rest')
);
}
diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
index 40f7fe6..c39b88f 100644
--- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
+++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
@@ -94,7 +94,7 @@ class EntityResource extends ResourceBase {
$this->validate($entity);
try {
$entity->save();
- watchdog('rest', 'Created entity %type with ID %id.', array('%type' => $entity->getEntityTypeId(), '%id' => $entity->id()));
+ $this->logger->notice('Created entity %type with ID %id.', array('%type' => $entity->getEntityTypeId(), '%id' => $entity->id()));
$url = url(strtr($this->pluginId, ':', '/') . '/' . $entity->id(), array('absolute' => TRUE));
// 201 Created responses have an empty body.
@@ -154,7 +154,7 @@ class EntityResource extends ResourceBase {
$this->validate($original_entity);
try {
$original_entity->save();
- watchdog('rest', 'Updated entity %type with ID %id.', array('%type' => $entity->getEntityTypeId(), '%id' => $entity->id()));
+ $this->logger->notice('Updated entity %type with ID %id.', array('%type' => $entity->getEntityTypeId(), '%id' => $entity->id()));
// Update responses have an empty body.
return new ResourceResponse(NULL, 204);
@@ -181,7 +181,7 @@ class EntityResource extends ResourceBase {
}
try {
$entity->delete();
- watchdog('rest', 'Deleted entity %type with ID %id.', array('%type' => $entity->getEntityTypeId(), '%id' => $entity->id()));
+ $this->logger->notice('Deleted entity %type with ID %id.', array('%type' => $entity->getEntityTypeId(), '%id' => $entity->id()));
// Delete responses have an empty body.
return new ResourceResponse(NULL, 204);
diff --git a/core/modules/search/src/Controller/SearchController.php b/core/modules/search/src/Controller/SearchController.php
index fe90bdc..0bb918f 100644
--- a/core/modules/search/src/Controller/SearchController.php
+++ b/core/modules/search/src/Controller/SearchController.php
@@ -11,6 +11,7 @@ use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Controller\ControllerBase;
use Drupal\search\SearchPageInterface;
use Drupal\search\SearchPageRepositoryInterface;
+use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
@@ -27,13 +28,23 @@ class SearchController extends ControllerBase {
protected $searchPageRepository;
/**
+ * A logger instance.
+ *
+ * @var \Psr\Log\LoggerInterface
+ */
+ protected $logger;
+
+ /**
* Constructs a new search controller.
*
* @param \Drupal\search\SearchPageRepositoryInterface $search_page_repository
* The search page repository.
+ * @param \Psr\Log\LoggerInterface $logger
+ * A logger instance.
*/
- public function __construct(SearchPageRepositoryInterface $search_page_repository) {
+ public function __construct(SearchPageRepositoryInterface $search_page_repository, LoggerInterface $logger) {
$this->searchPageRepository = $search_page_repository;
+ $this->logger = $logger;
}
/**
@@ -41,7 +52,8 @@ class SearchController extends ControllerBase {
*/
public static function create(ContainerInterface $container) {
return new static(
- $container->get('search.search_page_repository')
+ $container->get('search.search_page_repository'),
+ $container->get('logger.factory')->get('search')
);
}
@@ -77,7 +89,7 @@ class SearchController extends ControllerBase {
if ($plugin->isSearchExecutable()) {
// Log the search.
if ($this->config('search.settings')->get('logging')) {
- watchdog('search', 'Searched %type for %keys.', array('%keys' => $keys, '%type' => $entity->label()), WATCHDOG_NOTICE);
+ $this->logger->notice('Searched %type for %keys.', array('%keys' => $keys, '%type' => $entity->label()));
}
// Collect the search results.
diff --git a/core/modules/system/src/Controller/FormAjaxController.php b/core/modules/system/src/Controller/FormAjaxController.php
index be4c98d..4fb99d0 100644
--- a/core/modules/system/src/Controller/FormAjaxController.php
+++ b/core/modules/system/src/Controller/FormAjaxController.php
@@ -8,6 +8,9 @@
namespace Drupal\system\Controller;
use Drupal\Core\Form\FormState;
+use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
+use Psr\Log\LoggerInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
@@ -15,7 +18,33 @@ use Symfony\Component\HttpKernel\Exception\HttpException;
/**
* Defines a controller to respond to form Ajax requests.
*/
-class FormAjaxController {
+class FormAjaxController implements ContainerInjectionInterface {
+
+ /**
+ * A logger instance.
+ *
+ * @var \Psr\Log\LoggerInterface
+ */
+ protected $logger;
+
+ /**
+ * Constructs a FormAjaxController object.
+ *
+ * @param \Psr\Log\LoggerInterface $logger
+ * A logger instance.
+ */
+ public function __construct(LoggerInterface $logger) {
+ $this->logger = $logger;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container) {
+ return new static(
+ $container->get('logger.factory')->get('ajax')
+ );
+ }
/**
* Processes an Ajax form submission.
@@ -82,7 +111,7 @@ class FormAjaxController {
// system/ajax without actually viewing the concerned form in the browser.
// This is likely a hacking attempt as it never happens under normal
// circumstances.
- watchdog('ajax', 'Invalid form POST data.', array(), WATCHDOG_WARNING);
+ $this->logger->warning('Invalid form POST data.');
throw new BadRequestHttpException();
}
diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php
index b6ea3e9..09457df 100644
--- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php
@@ -34,7 +34,7 @@ class Desaturate extends GDImageToolkitOperationBase {
protected function execute(array $arguments) {
// PHP installations using non-bundled GD do not have imagefilter.
if (!function_exists('imagefilter')) {
- \Drupal::logger('image')->notice("The image '@file' could not be desaturated because the imagefilter() function is not available in this PHP installation.", array('@file' => $this->getToolkit()->getImage()->getSource()));
+ $this->logger->notice("The image '@file' could not be desaturated because the imagefilter() function is not available in this PHP installation.", array('@file' => $this->getToolkit()->getImage()->getSource()));
return FALSE;
}
diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php
index 7191a62..48d2549 100644
--- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php
@@ -42,7 +42,7 @@ class Rotate extends GDImageToolkitOperationBase {
protected function execute(array $arguments) {
// PHP installations using non-bundled GD do not have imagerotate.
if (!function_exists('imagerotate')) {
- \Drupal::logger('image')->notice('The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', array('%file' => $this->getToolkit()->getImage()->getSource()));
+ $this->logger->notice('The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', array('%file' => $this->getToolkit()->getImage()->getSource()));
return FALSE;
}
diff --git a/core/modules/taxonomy/src/Form/TermDeleteForm.php b/core/modules/taxonomy/src/Form/TermDeleteForm.php
index 7851734..fcd0326 100644
--- a/core/modules/taxonomy/src/Form/TermDeleteForm.php
+++ b/core/modules/taxonomy/src/Form/TermDeleteForm.php
@@ -65,7 +65,7 @@ class TermDeleteForm extends ContentEntityConfirmFormBase {
taxonomy_check_vocabulary_hierarchy($vocabulary, array('tid' => $this->entity->id()));
drupal_set_message($this->t('Deleted term %name.', array('%name' => $this->entity->getName())));
- watchdog('taxonomy', 'Deleted term %name.', array('%name' => $this->entity->getName()), WATCHDOG_NOTICE);
+ $this->logger('taxonomy')->notice('Deleted term %name.', array('%name' => $this->entity->getName()));
$form_state['redirect_route'] = $this->getCancelUrl();
}
diff --git a/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php b/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php
index 52348fb..1494d0a 100644
--- a/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php
+++ b/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php
@@ -57,7 +57,7 @@ class VocabularyDeleteForm extends EntityConfirmFormBase {
public function submit(array $form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message($this->t('Deleted vocabulary %name.', array('%name' => $this->entity->label())));
- watchdog('taxonomy', 'Deleted vocabulary %name.', array('%name' => $this->entity->label()), WATCHDOG_NOTICE);
+ $this->logger('taxonomy')->notice('Deleted vocabulary %name.', array('%name' => $this->entity->label()));
$form_state['redirect_route'] = $this->getCancelUrl();
}
diff --git a/core/modules/taxonomy/src/Form/VocabularyResetForm.php b/core/modules/taxonomy/src/Form/VocabularyResetForm.php
index e32aec8..5382f71 100644
--- a/core/modules/taxonomy/src/Form/VocabularyResetForm.php
+++ b/core/modules/taxonomy/src/Form/VocabularyResetForm.php
@@ -84,7 +84,7 @@ class VocabularyResetForm extends EntityConfirmFormBase {
public function save(array $form, FormStateInterface $form_state) {
$this->termStorage->resetWeights($this->entity->id());
drupal_set_message($this->t('Reset vocabulary %name to alphabetical order.', array('%name' => $this->entity->label())));
- watchdog('taxonomy', 'Reset vocabulary %name to alphabetical order.', array('%name' => $this->entity->label()), WATCHDOG_NOTICE);
+ $this->logger('taxonomy')->notice('Reset vocabulary %name to alphabetical order.', array('%name' => $this->entity->label()));
$form_state['redirect_route'] = $this->entity->urlInfo('edit-form');
}
diff --git a/core/modules/taxonomy/src/TermForm.php b/core/modules/taxonomy/src/TermForm.php
index 89aeac2..25873a3 100644
--- a/core/modules/taxonomy/src/TermForm.php
+++ b/core/modules/taxonomy/src/TermForm.php
@@ -141,11 +141,11 @@ class TermForm extends ContentEntityForm {
switch ($term->save()) {
case SAVED_NEW:
drupal_set_message($this->t('Created new term %term.', array('%term' => $term->getName())));
- watchdog('taxonomy', 'Created new term %term.', array('%term' => $term->getName()), WATCHDOG_NOTICE, l($this->t('Edit'), 'taxonomy/term/' . $term->id() . '/edit'));
+ $this->logger('taxonomy')->notice('Created new term %term.', array('%term' => $term->getName(), 'link' => l($this->t('Edit'), 'taxonomy/term/' . $term->id() . '/edit')));
break;
case SAVED_UPDATED:
drupal_set_message($this->t('Updated term %term.', array('%term' => $term->getName())));
- watchdog('taxonomy', 'Updated term %term.', array('%term' => $term->getName()), WATCHDOG_NOTICE, l($this->t('Edit'), 'taxonomy/term/' . $term->id() . '/edit'));
+ $this->logger('taxonomy')->notice('Updated term %term.', array('%term' => $term->getName(), 'link' => l($this->t('Edit'), 'taxonomy/term/' . $term->id() . '/edit')));
break;
}
diff --git a/core/modules/taxonomy/src/VocabularyForm.php b/core/modules/taxonomy/src/VocabularyForm.php
index 01ddc08..d389115 100644
--- a/core/modules/taxonomy/src/VocabularyForm.php
+++ b/core/modules/taxonomy/src/VocabularyForm.php
@@ -142,13 +142,13 @@ class VocabularyForm extends EntityForm {
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created new vocabulary %name.', array('%name' => $vocabulary->name)));
- watchdog('taxonomy', 'Created new vocabulary %name.', array('%name' => $vocabulary->name), WATCHDOG_NOTICE, $edit_link);
+ $this->logger('taxonomy')->notice('Created new vocabulary %name.', array('%name' => $vocabulary->name, 'link' => $edit_link));
$form_state['redirect_route'] = $vocabulary->urlInfo('overview-form');
break;
case SAVED_UPDATED:
drupal_set_message($this->t('Updated vocabulary %name.', array('%name' => $vocabulary->name)));
- watchdog('taxonomy', 'Updated vocabulary %name.', array('%name' => $vocabulary->name), WATCHDOG_NOTICE, $edit_link);
+ $this->logger('taxonomy')->notice('Updated vocabulary %name.', array('%name' => $vocabulary->name, 'link' => $edit_link));
$form_state['redirect_route']['route_name'] = 'taxonomy.vocabulary_list';
break;
}
diff --git a/core/modules/user/src/Form/UserCancelForm.php b/core/modules/user/src/Form/UserCancelForm.php
index 031a27a..8e48df9 100644
--- a/core/modules/user/src/Form/UserCancelForm.php
+++ b/core/modules/user/src/Form/UserCancelForm.php
@@ -135,7 +135,7 @@ class UserCancelForm extends ContentEntityConfirmFormBase {
$this->entity->save();
_user_mail_notify('cancel_confirm', $this->entity);
drupal_set_message($this->t('A confirmation request to cancel your account has been sent to your email address.'));
- watchdog('user', 'Sent account cancellation request to %name %email.', array('%name' => $this->entity->label(), '%email' => '<' . $this->entity->getEmail() . '>'), WATCHDOG_NOTICE);
+ $this->logger('user')->notice('Sent account cancellation request to %name %email.', array('%name' => $this->entity->label(), '%email' => '<' . $this->entity->getEmail() . '>'));
$form_state['redirect_route'] = array(
'route_name' => 'user.view',
diff --git a/core/modules/user/src/Form/UserLoginForm.php b/core/modules/user/src/Form/UserLoginForm.php
index 9ba6217..7ba3db7 100644
--- a/core/modules/user/src/Form/UserLoginForm.php
+++ b/core/modules/user/src/Form/UserLoginForm.php
@@ -217,12 +217,12 @@ class UserLoginForm extends FormBase {
$this->setFormError('name', $form_state, $this->t('Sorry, unrecognized username or password. <a href="@password">Have you forgotten your password?</a>', array('@password' => url('user/password', array('query' => array('name' => $form_state['values']['name']))))));
$accounts = $this->userStorage->loadByProperties(array('name' => $form_state['values']['name']));
if (!empty($accounts)) {
- watchdog('user', 'Login attempt failed for %user.', array('%user' => $form_state['values']['name']));
+ $this->logger('user')->notice('Login attempt failed for %user.', array('%user' => $form_state['values']['name']));
}
else {
// If the username entered is not a valid user,
// only store the IP address.
- watchdog('user', 'Login attempt failed from %ip.', array('%ip' => $this->getRequest()->getClientIp()));
+ $this->logger('user')->notice('Login attempt failed from %ip.', array('%ip' => $this->getRequest()->getClientIp()));
}
}
}
diff --git a/core/modules/user/src/Form/UserPasswordForm.php b/core/modules/user/src/Form/UserPasswordForm.php
index 5905282..5997048 100644
--- a/core/modules/user/src/Form/UserPasswordForm.php
+++ b/core/modules/user/src/Form/UserPasswordForm.php
@@ -134,7 +134,7 @@ class UserPasswordForm extends FormBase {
// Mail one time login URL and instructions using current language.
$mail = _user_mail_notify('password_reset', $account, $langcode);
if (!empty($mail)) {
- watchdog('user', 'Password reset instructions mailed to %name at %email.', array('%name' => $account->getUsername(), '%email' => $account->getEmail()));
+ $this->logger('user')->notice('Password reset instructions mailed to %name at %email.', array('%name' => $account->getUsername(), '%email' => $account->getEmail()));
drupal_set_message($this->t('Further instructions have been sent to your email address.'));
}
diff --git a/core/modules/user/src/Form/UserRoleDelete.php b/core/modules/user/src/Form/UserRoleDelete.php
index 4288170..2e80fc6 100644
--- a/core/modules/user/src/Form/UserRoleDelete.php
+++ b/core/modules/user/src/Form/UserRoleDelete.php
@@ -42,7 +42,7 @@ class UserRoleDelete extends EntityConfirmFormBase {
*/
public function submit(array $form, FormStateInterface $form_state) {
$this->entity->delete();
- watchdog('user', 'Role %name has been deleted.', array('%name' => $this->entity->label()));
+ $this->logger('user')->notice('Role %name has been deleted.', array('%name' => $this->entity->label()));
drupal_set_message($this->t('Role %name has been deleted.', array('%name' => $this->entity->label())));
$form_state['redirect_route'] = $this->getCancelUrl();
}
diff --git a/core/modules/user/src/RegisterForm.php b/core/modules/user/src/RegisterForm.php
index f3f2511..c20d240 100644
--- a/core/modules/user/src/RegisterForm.php
+++ b/core/modules/user/src/RegisterForm.php
@@ -116,7 +116,7 @@ class RegisterForm extends AccountForm {
$form_state['user'] = $account;
$form_state['values']['uid'] = $account->id();
- watchdog('user', 'New user: %name %email.', array('%name' => $form_state['values']['name'], '%email' => '<' . $form_state['values']['mail'] . '>'), WATCHDOG_NOTICE, l($this->t('Edit'), 'user/' . $account->id() . '/edit'));
+ $this->logger('user')->notice('New user: %name %email.', array('%name' => $form_state['values']['name'], '%email' => '<' . $form_state['values']['mail'] . '>', 'type' => l($this->t('Edit'), 'user/' . $account->id() . '/edit')));
// Add plain text password into user account to generate mail tokens.
$account->password = $pass;
diff --git a/core/modules/user/src/RoleForm.php b/core/modules/user/src/RoleForm.php
index 0587041..57c4d46 100644
--- a/core/modules/user/src/RoleForm.php
+++ b/core/modules/user/src/RoleForm.php
@@ -62,11 +62,11 @@ class RoleForm extends EntityForm {
$edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo());
if ($status == SAVED_UPDATED) {
drupal_set_message($this->t('Role %label has been updated.', array('%label' => $entity->label())));
- watchdog('user', 'Role %label has been updated.', array('%label' => $entity->label()), WATCHDOG_NOTICE, $edit_link);
+ $this->logger('user')->notice('Role %label has been updated.', array('%label' => $entity->label(), 'link' => $edit_link));
}
else {
drupal_set_message($this->t('Role %label has been added.', array('%label' => $entity->label())));
- watchdog('user', 'Role %label has been added.', array('%label' => $entity->label()), WATCHDOG_NOTICE, $edit_link);
+ $this->logger('user')->notice('Role %label has been added.', array('%label' => $entity->label(), 'link' => $edit_link));
}
$form_state['redirect_route']['route_name'] = 'user.role_list';
}
diff --git a/core/tests/Drupal/Tests/Core/Image/ImageTest.php b/core/tests/Drupal/Tests/Core/Image/ImageTest.php
index 828a1a1..b8db186 100644
--- a/core/tests/Drupal/Tests/Core/Image/ImageTest.php
+++ b/core/tests/Drupal/Tests/Core/Image/ImageTest.php
@@ -83,9 +83,10 @@ class ImageTest extends UnitTestCase {
*/
protected function getToolkitOperationMock($class_name, ImageToolkitInterface $toolkit) {
$mock_builder = $this->getMockBuilder('Drupal\system\Plugin\ImageToolkit\Operation\gd\\' . $class_name);
+ $logger = $this->getMock('Psr\Log\LoggerInterface');
return $mock_builder
->setMethods(array('execute'))
- ->setConstructorArgs(array(array(), '', array(), $toolkit))
+ ->setConstructorArgs(array(array(), '', array(), $toolkit, $logger))
->getMock();
}