diff --git a/core/core.services.yml b/core/core.services.yml index fd9028c7d7dbf787c2bca76d2ce40a2c503f4ebd..a58f7796b8f5e075eea311f011f3253c2042052c 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 6595e6f822482cab16ad0b4177cb35c8ba050187..b5e27deac3f45b8da60173c025e927f1201f043f 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -640,7 +640,7 @@ public static function isConfigSyncing() { * 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 e90dcf676c09ed225de870ccd5da6f04205a86cf..a6b315c2189de71817cf254244f1b534b63ee7dc 100644 --- a/core/lib/Drupal/Core/Form/FormBase.php +++ b/core/lib/Drupal/Core/Form/FormBase.php @@ -46,6 +46,13 @@ abstract class FormBase implements FormInterface, ContainerInjectionInterface { */ protected $configFactory; + /** + * The logger factory. + * + * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface + */ + protected $loggerFactory; + /** * {@inheritdoc} */ @@ -187,4 +194,20 @@ protected function setFormError($name, FormStateInterface $form_state, $message 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 b3ae30de0390187df1d79597d1311e70ffcea9d9..1a5c19bd69d0091a4e20cb2e4c04bb52487d8da0 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php @@ -10,6 +10,7 @@ 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 { @@ -27,6 +28,14 @@ abstract class ImageToolkitBase extends PluginBase implements ImageToolkitInterf */ protected $operationManager; + /** + * A logger instance. + * + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + + /** * Constructs an ImageToolkitBase object. * @@ -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 @@ public function apply($operation, array $arguments = array()) { 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 789ef5aae233b33fb8867b82a72b3a5a87511dc5..270f8706dd895b9bc3d4820db91cabdea09d72e2 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php @@ -12,6 +12,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Component\Plugin\Factory\DefaultFactory; +use Psr\Log\LoggerInterface; /** * Manages toolkit plugins. @@ -32,6 +33,13 @@ class ImageToolkitManager extends DefaultPluginManager { */ protected $operationManager; + /** + * A logger instance. + * + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + /** * Constructs the ImageToolkitManager object. * @@ -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 @@ public function getAvailableToolkits() { 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 6b66c298095d8ebc142f05e75163679b3e12c794..eb13a9fe38ef29eda47be5bf235a9168c72cb24a 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php @@ -10,6 +10,7 @@ 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 { @@ -20,6 +21,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. * @@ -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 a18678ba955c8cb29528d9322d8d6caf29c1707a..20ecc5579bc92e88005630c9775fe3983d7b998d 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php @@ -13,12 +13,20 @@ 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. */ class ImageToolkitOperationManager extends DefaultPluginManager implements ImageToolkitOperationManagerInterface { + /** + * A logger instance. + * + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + /** * Constructs the ImageToolkitOperationManager object. * @@ -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 @@ function ($definition) use ($toolkit_id, $operation) { 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 a65d574fa05c59c63fadc90d2e218100a6e69606..95b8ebbd89be96126e5e283bb85435406315f05d 100644 --- a/core/modules/action/src/Form/ActionDeleteForm.php +++ b/core/modules/action/src/Form/ActionDeleteForm.php @@ -43,7 +43,7 @@ public function getCancelUrl() { 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 a9a00a9337846dcd0e421f989459ce783cbf77e6..b973204511c718b600158037dc54b0d1c6cc55f7 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\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Utility\Token; +use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -39,6 +40,13 @@ class EmailAction extends ConfigurableActionBase implements ContainerFactoryPlug */ protected $storage; + /** + * A logger instance. + * + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + /** * Constructs a EmailAction object. * @@ -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 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition 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 @@ public function execute($entity = NULL) { $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 6d9d3ea2673f0e973bbb597e54ded403fd32e098..12e7c6e068d3e941a5e83a107c05d38af2072c15 100644 --- a/core/modules/aggregator/src/FeedForm.php +++ b/core/modules/aggregator/src/FeedForm.php @@ -70,7 +70,7 @@ public function save(array $form, FormStateInterface $form_state) { $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 83c171e4587a51da4fe3c22aff4f51895d50c7ff..678654404133b89b5d98f3ae5645e6f71be7c8b3 100644 --- a/core/modules/aggregator/src/Form/FeedDeleteForm.php +++ b/core/modules/aggregator/src/Form/FeedDeleteForm.php @@ -42,7 +42,7 @@ public function getConfirmText() { */ 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 3bed94fb4efd52bff252fdc04fb25d7a693883fa..6dc0fdb0b5a8d3d1d21df8d102ff894f224e9943 100644 --- a/core/modules/aggregator/src/Form/OpmlFeedAdd.php +++ b/core/modules/aggregator/src/Form/OpmlFeedAdd.php @@ -125,7 +125,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $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 ce3669651640d2f721f7a5809a1f5b7695821fe1..8695d25db36c320a8b09fc593567da6003963b5c 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\Core\Plugin\ContainerFactoryPluginInterface; use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\RequestException; +use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -35,14 +36,24 @@ 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 @@ public function __construct(ClientInterface $http_client) { */ 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 @@ public function fetch(FeedInterface $feed) { 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 b607ba92cc0d766ff922f464aa29c5a0b93ce7b6..273454059c6a74f1898e1070ad7209e78db87576 100644 --- a/core/modules/ban/src/Form/BanDelete.php +++ b/core/modules/ban/src/Form/BanDelete.php @@ -91,7 +91,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $ban_id = */ 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 1524f4241e9203d5dd40341b10283f972d420883..86ffc0c9033fd170cb8a43d75fbb624d7032dd46 100644 --- a/core/modules/block_content/src/BlockContentForm.php +++ b/core/modules/block_content/src/BlockContentForm.php @@ -194,16 +194,17 @@ public function save(array $form, FormStateInterface $form_state) { $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 025d673a6d56f4ddc1ae6d3d89ce428491a9d716..93c86a3e0d114659b7c0d61fdf3f3381adee42c0 100644 --- a/core/modules/block_content/src/BlockContentTypeForm.php +++ b/core/modules/block_content/src/BlockContentTypeForm.php @@ -93,13 +93,14 @@ public function save(array $form, FormStateInterface $form_state) { $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 88249ae28656550090588d1fc0f8c4e86d002bae..1fbb99a6a77496afe9be39463bf513c36b55b43f 100644 --- a/core/modules/block_content/src/Form/BlockContentDeleteForm.php +++ b/core/modules/block_content/src/Form/BlockContentDeleteForm.php @@ -57,7 +57,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { 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 decda49dc235a7fefcf8a557638f40d9da6ab05a..b7c99a690e020f2b34726b38c09feaee7cf189eb 100644 --- a/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php +++ b/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php @@ -86,7 +86,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { 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 9a342f086fa694b13fb886cfa1c79f67975f75f4..39d6e0de17c694c5fa169760a28482fd6e702dbc 100644 --- a/core/modules/book/src/Form/BookAdminEditForm.php +++ b/core/modules/book/src/Form/BookAdminEditForm.php @@ -120,7 +120,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $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 9701e49f779ac30633738084ef3261957f723079..343d93a6cfb82fa7983d19644b3f9580a4c50815 100644 --- a/core/modules/comment/src/CommentForm.php +++ b/core/modules/comment/src/CommentForm.php @@ -364,6 +364,7 @@ public function save(array $form, FormStateInterface $form_state) { $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 @@ public function save(array $form, FormStateInterface $form_state) { $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 @@ public function save(array $form, FormStateInterface $form_state) { $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 39fe5382527bec0f5e13b3383621a42fc0577f5a..fa3494cc80ee4aa5187688a1d627cb414a4c2732 100644 --- a/core/modules/comment/src/Form/ConfirmDeleteMultiple.php +++ b/core/modules/comment/src/Form/ConfirmDeleteMultiple.php @@ -121,7 +121,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { 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 1ee7b4c4a5d50673c8085bfe30fc5755ef95dda4..a6d01e861b49d0ff391a4fbb4f484a558bbd0d8d 100644 --- a/core/modules/comment/src/Form/DeleteForm.php +++ b/core/modules/comment/src/Form/DeleteForm.php @@ -51,7 +51,7 @@ public function submit(array $form, FormStateInterface $form_state) { // 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 df91084619682066bb141238ab54f1feb51ee8d7..0b697d1166333abaf5550d5b6cd9656ec657805d 100644 --- a/core/modules/contact/src/CategoryForm.php +++ b/core/modules/contact/src/CategoryForm.php @@ -100,11 +100,11 @@ public function save(array $form, FormStateInterface $form_state) { 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 5fddb0855abed51c4a9ff8caa0e5f15a4462acd8..aca91616cd8e2ff71201ebb46eb07ea687bd5dcf 100644 --- a/core/modules/contact/src/Form/CategoryDeleteForm.php +++ b/core/modules/contact/src/Form/CategoryDeleteForm.php @@ -43,7 +43,7 @@ public function getConfirmText() { 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 30ac4105602082dc51391e34df210750954087f0..69c804a6c00ba0de04dd2296cc9ba02792472dea 100644 --- a/core/modules/contact/src/MessageForm.php +++ b/core/modules/contact/src/MessageForm.php @@ -239,14 +239,14 @@ public function save(array $form, FormStateInterface $form_state) { $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 9c30edc7a661fd1cb2038c334148e87bb3b56a6c..3b2d943a4004cec62cd17246f1c8c9e928044771 100644 --- a/core/modules/filter/src/Plugin/Filter/FilterNull.php +++ b/core/modules/filter/src/Plugin/Filter/FilterNull.php @@ -40,7 +40,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition // 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 94cdf1126ce77171b14508ebac856efd7402f4d3..ddde478534e843b8877f7e2a8971a22079020b8e 100644 --- a/core/modules/forum/src/Form/DeleteForm.php +++ b/core/modules/forum/src/Form/DeleteForm.php @@ -67,7 +67,7 @@ public function buildForm(array $form, FormStateInterface $form_state, TermInter 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 300738058b413cce79ea05b6aa1cd17c18b88c04..42904520053c63ef9ad0018217bd925d1cdddddf 100644 --- a/core/modules/forum/src/Form/ForumForm.php +++ b/core/modules/forum/src/Form/ForumForm.php @@ -82,13 +82,13 @@ public function save(array $form, FormStateInterface $form_state) { 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 bf4f9d9941fa576fe58b3f9aceab64b63b18e692..3e4bcf00d1486be4b46b583eab2dc42a29778ba3 100644 --- a/core/modules/image/src/Controller/ImageStyleDownloadController.php +++ b/core/modules/image/src/Controller/ImageStyleDownloadController.php @@ -12,6 +12,7 @@ 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; @@ -38,6 +39,13 @@ class ImageStyleDownloadController extends FileDownloadController { */ protected $imageFactory; + /** + * A logger instance. + * + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + /** * Constructs a ImageStyleDownloadController object. * @@ -45,10 +53,13 @@ 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) { + public function __construct(LockBackendInterface $lock, ImageFactory $image_factory, LoggerInterface $logger) { $this->lock = $lock; $this->imageFactory = $image_factory; + $this->logger = $logger; } /** @@ -57,7 +68,8 @@ 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('image.factory'), + $container->get('logger.factory')->get('image') ); } @@ -118,7 +130,7 @@ public function deliver(Request $request, $scheme, ImageStyleInterface $image_st // 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 @@ public function deliver(Request $request, $scheme, ImageStyleInterface $image_st 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 10cd626ef4200552d4ad866554cd2598bafe23e8..a122aa4ec62313dacdab91fa14561de1a37bb653 100644 --- a/core/modules/image/src/Entity/ImageStyle.php +++ b/core/modules/image/src/Entity/ImageStyle.php @@ -272,7 +272,7 @@ public function createDerivative($original_uri, $derivative_uri) { // 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 @@ public function createDerivative($original_uri, $derivative_uri) { 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 91bdc2924fb94f152c093db5a15930c7e7d26643..dac79663c7188872c5459e5f1769cd583fe20b2d 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. @@ -28,13 +31,33 @@ 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 0edac982749d6a1ffa86ef28e621c2719a91b1a4..8522b9e44fc69db02133ad6d33b62098010c50ae 100644 --- a/core/modules/image/src/Plugin/ImageEffect/CropImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/CropImageEffect.php @@ -29,7 +29,7 @@ public function applyEffect(ImageInterface $image) { $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 4d899c666cc84b2bb5c91867afdeae1dc38a7c66..97d31d8221cd44beaacb6dd37a8a92f2f64c20b5 100644 --- a/core/modules/image/src/Plugin/ImageEffect/DesaturateImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/DesaturateImageEffect.php @@ -32,7 +32,7 @@ public function transformDimensions(array &$dimensions) { */ 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 15f00805bfd28b9328d7e926af38a24b885e1807..1edf23cdec88896a832ce61f35023896bac3f116 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 7f29aaff1180c2cff0a0930c81af13312ef6bf18..eaaa860ffaa1dd786e1740eeffe0faf65eb6e3d5 100644 --- a/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php @@ -47,7 +47,7 @@ public function applyEffect(ImageInterface $image) { } 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 7fed9b19468a9a4951bd977328488fef2f7ef299..ca9479f48348771039a737eab26c7fcee19b82e4 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 a5dae9a7cd35a1aec2367c08985d585f5e92381c..a6e1d233df260be3d2842e4d36d6ce1a6e19b3b8 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 6c582d3d38afe385e1b0388b9dfca7e00f741947..bb1939d600e08c99a64d6ab88263c25d35bc6b5c 100644 --- a/core/modules/locale/src/Form/TranslateEditForm.php +++ b/core/modules/locale/src/Form/TranslateEditForm.php @@ -166,7 +166,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) { 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 2332b40ec94b61d5bf18d1456e0bffdb0f7ecea7..33712e4fb466b41fc5fc8f31a62509af5d280480 100644 --- a/core/modules/menu_ui/src/Form/MenuDeleteForm.php +++ b/core/modules/menu_ui/src/Form/MenuDeleteForm.php @@ -117,6 +117,6 @@ public function submit(array $form, FormStateInterface $form_state) { $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 d115736a4e9b5710adbe2c61887d0b0539fd559c..40123d56a6b3275775e3846faf2e4e2d7abc411e 100644 --- a/core/modules/menu_ui/src/MenuForm.php +++ b/core/modules/menu_ui/src/MenuForm.php @@ -185,11 +185,11 @@ public function save(array $form, FormStateInterface $form_state) { $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 a067ccb0693bf4d04d55d9566792c0dbbfdbdcb2..4f0356e8ffc399f1875e1052ee770aa291b98a29 100644 --- a/core/modules/node/src/Form/DeleteMultiple.php +++ b/core/modules/node/src/Form/DeleteMultiple.php @@ -121,7 +121,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $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 19faa67a5e5fca5c11108bdc694daa4088393f9f..87df223a5055b88aa7c5a864c86a4ed2c774bc1f 100644 --- a/core/modules/node/src/Form/NodeDeleteForm.php +++ b/core/modules/node/src/Form/NodeDeleteForm.php @@ -74,7 +74,7 @@ public function getConfirmText() { */ 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 0ab753dc0a46c7f459a900d341c2c14677e92c77..4df72920cd3ca14a16035a862af3ee84f1126216 100644 --- a/core/modules/node/src/Form/NodeRevisionDeleteForm.php +++ b/core/modules/node/src/Form/NodeRevisionDeleteForm.php @@ -120,7 +120,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $node_rev 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 147036fab8c2e6da4f4b0d27cb21f0e72eba2b40..c6dc728fe2d36ea62b4ce449b7ba7dc0a771b21e 100644 --- a/core/modules/node/src/Form/NodeRevisionRevertForm.php +++ b/core/modules/node/src/Form/NodeRevisionRevertForm.php @@ -113,7 +113,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $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 0c23ced81c57258009ba9e2e50daa457d70d9e85..5cf4e2ac6052471372c1e2f1730c4760e0c5208c 100644 --- a/core/modules/node/src/Form/NodeTypeDeleteConfirm.php +++ b/core/modules/node/src/Form/NodeTypeDeleteConfirm.php @@ -87,7 +87,7 @@ public function submit(array $form, FormStateInterface $form_state) { $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 bf4b869fb81bc2b82325b4deb9fb12368e9c4e1d..085cf2ccdc25e1c53c3ded7e83c0e9f96f523873 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -433,15 +433,15 @@ public function save(array $form, FormStateInterface $form_state) { $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 f8cf92791751829113b4a37246a220f822fdb49b..9534e301dbfb29db0eb220d5a3aac5729dd30198 100644 --- a/core/modules/node/src/NodeTypeForm.php +++ b/core/modules/node/src/NodeTypeForm.php @@ -190,7 +190,8 @@ public function save(array $form, FormStateInterface $form_state) { } 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 e614e0ee6a30a261ac70ce8b057017ad4c011bac..1d438b6b2826bb4ddf7f5b0c96aaf193098708dc 100644 --- a/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php +++ b/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php @@ -40,7 +40,7 @@ public function getConfirmText() { 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 7a38d1231c19263ef00f1bb9c96eaac7c8a00d8e..de6ca92712774a6b099371257e58c36d9e88452f 100644 --- a/core/modules/responsive_image/src/ResponsiveImageMappingForm.php +++ b/core/modules/responsive_image/src/ResponsiveImageMappingForm.php @@ -125,7 +125,7 @@ public function save(array $form, FormStateInterface $form_state) { $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 cab3b59b7fd416b3871622058fff746e6cc0df51..0cf3281215bea96a792ee95ef2c198ea0d46a431 100644 --- a/core/modules/rest/src/Plugin/ResourceBase.php +++ b/core/modules/rest/src/Plugin/ResourceBase.php @@ -10,6 +10,7 @@ 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; @@ -33,6 +34,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. * @@ -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 @@ public static function create(ContainerInterface $container, array $configuratio $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 40f7fe685f974decf4c0f5469be74f370cdd916b..c39b88f150153b64adca43e7a553211134256527 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 @@ public function post(EntityInterface $entity = NULL) { $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 @@ public function patch(EntityInterface $original_entity, EntityInterface $entity $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 @@ public function delete(EntityInterface $entity) { } 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 fe90bdc9f20486081ada86b88e016fc60ffd7e4f..0bb918f663b431313d6101dada83eaed93a9b3ce 100644 --- a/core/modules/search/src/Controller/SearchController.php +++ b/core/modules/search/src/Controller/SearchController.php @@ -11,6 +11,7 @@ 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; @@ -26,14 +27,24 @@ 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 @@ public function __construct(SearchPageRepositoryInterface $search_page_repositor */ 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 @@ public function view(Request $request, SearchPageInterface $entity) { 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 be4c98d155e0a009195bf0b85a6cb9db80562fc7..4fb99d0ca76c603976a3d06d7c0eb87226f73db5 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 @@ /** * 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 @@ protected function getForm(Request $request) { // 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 b6ea3e95a71d2adb95ba545884a9d06cadf2a9a4..09457df58ed7ee1692fc7255df8b3e16537aa4eb 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 @@ protected function arguments() { 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 7191a62997773731592dd55006b25e82feedc5c1..48d254952c6ea5759f6f3537d528ab877b5558cf 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 @@ protected function arguments() { 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 7851734e1ea8f3db012ec73f400d8708f17e2097..fcd0326c8eb6092e9af5f878450a05a9f562e204 100644 --- a/core/modules/taxonomy/src/Form/TermDeleteForm.php +++ b/core/modules/taxonomy/src/Form/TermDeleteForm.php @@ -65,7 +65,7 @@ public function submit(array $form, FormStateInterface $form_state) { 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 52348fb5b76bda4f4142913c1fd2e8269b76b130..1494d0af704709e0cd4227b1b4c0870475ecac88 100644 --- a/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php +++ b/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php @@ -57,7 +57,7 @@ public function getConfirmText() { 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 e32aec86b03857936ca2c946bb570156a0dc580d..5382f718e469ab0dc00094922b358dea9f224b78 100644 --- a/core/modules/taxonomy/src/Form/VocabularyResetForm.php +++ b/core/modules/taxonomy/src/Form/VocabularyResetForm.php @@ -84,7 +84,7 @@ public function getConfirmText() { 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 89aeac2b4aebe47ad8937b8085bffbb27eb0fb50..25873a3c9cf1f76e02d9afaf18c7d5555559f7bf 100644 --- a/core/modules/taxonomy/src/TermForm.php +++ b/core/modules/taxonomy/src/TermForm.php @@ -141,11 +141,11 @@ public function save(array $form, FormStateInterface $form_state) { 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 01ddc08e76507019ca03e8a85cfbf274d9c5d8ab..d389115b82ba6d46b03a025b19ab369d6c1f3377 100644 --- a/core/modules/taxonomy/src/VocabularyForm.php +++ b/core/modules/taxonomy/src/VocabularyForm.php @@ -142,13 +142,13 @@ public function save(array $form, FormStateInterface $form_state) { 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 031a27a539e4e9f678725731ea8e2c72d2eea593..8e48df9b48e66b68ae4fb7691922c9e340d612c3 100644 --- a/core/modules/user/src/Form/UserCancelForm.php +++ b/core/modules/user/src/Form/UserCancelForm.php @@ -135,7 +135,7 @@ public function submit(array $form, FormStateInterface $form_state) { $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 9ba621716bed0e6295e7552522d2720987a51d24..7ba3db7a82ae289185742a9899bc4cdc45493c80 100644 --- a/core/modules/user/src/Form/UserLoginForm.php +++ b/core/modules/user/src/Form/UserLoginForm.php @@ -217,12 +217,12 @@ public function validateFinal(array &$form, FormStateInterface $form_state) { $this->setFormError('name', $form_state, $this->t('Sorry, unrecognized username or password. Have you forgotten your password?', 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 59052820c1afe252b62aede7263dd51845554321..59970482b57adf4da2499f2354104e6fbca426fd 100644 --- a/core/modules/user/src/Form/UserPasswordForm.php +++ b/core/modules/user/src/Form/UserPasswordForm.php @@ -134,7 +134,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // 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 428817072b57f9fc6f587a1cacef12f578f4d4c1..2e80fc6518b721c9424bd3972a0c8b76eb1926ad 100644 --- a/core/modules/user/src/Form/UserRoleDelete.php +++ b/core/modules/user/src/Form/UserRoleDelete.php @@ -42,7 +42,7 @@ public function getConfirmText() { */ 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 f3f251125fb97d06739986a2d8e4665691bc71bf..c20d240ec51809b40fc79abc89f722ae8b34f807 100644 --- a/core/modules/user/src/RegisterForm.php +++ b/core/modules/user/src/RegisterForm.php @@ -116,7 +116,7 @@ public function save(array $form, FormStateInterface $form_state) { $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 0587041080a8d154558347c75fb2af8a2ce97f73..57c4d46f89a2a7ac25edbf7080962b9229d1accd 100644 --- a/core/modules/user/src/RoleForm.php +++ b/core/modules/user/src/RoleForm.php @@ -62,11 +62,11 @@ public function save(array $form, FormStateInterface $form_state) { $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 828a1a114f5a1d1f8f26ffbd03bd71ef094ccd92..b8db186564f1711dd4189306efc4a52e093e4330 100644 --- a/core/tests/Drupal/Tests/Core/Image/ImageTest.php +++ b/core/tests/Drupal/Tests/Core/Image/ImageTest.php @@ -83,9 +83,10 @@ protected function getToolkitMock(array $stubs = array()) { */ 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(); }