Issue #2272481 by herom, ParisLiakos, tim.plunkett: Remove usages of watchdog() from forms, plugins and controllers.

8.0.x
Nathaniel Catchpole 2014-07-31 13:44:46 +01:00
parent ced85d104a
commit a91ef2b853
67 changed files with 292 additions and 101 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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 @@ 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);
}
}

View File

@ -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 {
@ -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 @@ 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;
}
}

View File

@ -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.
@ -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 @@ 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);
}
}

View File

@ -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 {
@ -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;
}
/**

View File

@ -13,12 +13,20 @@ 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.
*/
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 @@ 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);
}
/**

View File

@ -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();

View File

@ -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;
/**
@ -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 @@ 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));
}
}

View File

@ -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())));
}
}

View File

@ -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');
}

View File

@ -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;
}

View File

@ -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;
/**
@ -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 @@ 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;
}

View File

@ -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();
}

View File

@ -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));
}

View File

@ -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';

View File

@ -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');
}

View File

@ -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();
}

View File

@ -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())));
}
}
}

View File

@ -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.
}

View File

@ -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();

View File

@ -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();
}

View File

@ -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.

View File

@ -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();
}

View File

@ -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(),

View File

@ -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);
}

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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;
@ -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 @@ 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);
}
}

View File

@ -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;
}

View File

@ -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')
);
}
/**

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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));
}
}
}

View File

@ -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);
}
}

View File

@ -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');

View File

@ -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';

View File

@ -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())));

View File

@ -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(

View File

@ -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',

View File

@ -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();
}

View File

@ -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));
}

View File

@ -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';

View File

@ -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();
}

View File

@ -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

View File

@ -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;
@ -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 @@ 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')
);
}

View File

@ -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);

View File

@ -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;
@ -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 @@ 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.

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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');
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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',

View File

@ -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()));
}
}
}

View File

@ -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.'));
}

View File

@ -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();
}

View File

@ -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;

View File

@ -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';
}

View File

@ -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();
}