Skip to content

Commit

Permalink
Use logger channel service rather than logger.factory (#4148)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-m authored Mar 28, 2024
1 parent c091fdb commit 6c42374
Show file tree
Hide file tree
Showing 20 changed files with 181 additions and 195 deletions.
2 changes: 1 addition & 1 deletion modules/datastore/datastore.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ services:
class: \Drupal\datastore\EventSubscriber\DatastoreSubscriber
arguments:
- '@config.factory'
- '@logger.factory'
- '@dkan.datastore.logger_channel'
- '@dkan.datastore.service'
- '@dkan.datastore.service.resource_purger'
- '@dkan.datastore.import_job_store_factory'
Expand Down
2 changes: 1 addition & 1 deletion modules/datastore/drush.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ services:
arguments:
- '@dkan.datastore.service'
- '@dkan.common.dataset_info'
- '@logger.factory'
- '@dkan.datastore.logger_channel'
tags:
- { name: drush.command }
27 changes: 10 additions & 17 deletions modules/datastore/src/Commands/ReimportCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Drupal\datastore\Commands;

use Drupal\common\DatasetInfo;
use Drupal\Core\Logger\LoggerChannelFactory;
use Drupal\datastore\DatastoreService;
use Drush\Commands\DrushCommands;
use Psr\Log\LoggerInterface;

/**
* Drush command file for data store reimportation.
Expand All @@ -14,13 +14,6 @@
*/
class ReimportCommands extends DrushCommands {

/**
* Logger service.
*
* @var \Drupal\Core\Logger\LoggerChannelFactory
*/
protected $loggerFactory;

/**
* The datastore service.
*
Expand All @@ -42,17 +35,17 @@ class ReimportCommands extends DrushCommands {
* The dkan.datastore.service service.
* @param \Drupal\common\DatasetInfo $dataset_info
* Dataset information service.
* @param \Drupal\Core\Logger\LoggerChannelFactory $logger_factory
* LoggerChannelFactory service.
* @param \Psr\Log\LoggerInterface $loggerChannel
* Logger channel service.
*/
public function __construct(
DatastoreService $datastore_service,
DatasetInfo $dataset_info,
LoggerChannelFactory $logger_factory
LoggerInterface $loggerChannel
) {
$this->datastoreService = $datastore_service;
$this->datasetInfo = $dataset_info;
$this->loggerFactory = $logger_factory;
$this->setLogger($loggerChannel);
parent::__construct();
}

Expand All @@ -79,14 +72,14 @@ public function datastoreReimport(string $uuid) {
if ($distributions = $info['latest_revision']['distributions'] ?? FALSE) {
// Reimport whatever distributions we found.
$this->reimportDistributions($distributions);
$this->loggerFactory->get('datastore')->notice(count($info) . ' distribution(s) found for ' . $uuid);
$this->logger()->notice(count($info) . ' distribution(s) found for ' . $uuid);
}
else {
$this->loggerFactory->get('datastore')->error('Unable to find distributions for ' . $uuid);
$this->logger()->error('Unable to find distributions for ' . $uuid);
}
}
else {
$this->loggerFactory->get('datastore')->error('Unable to find dataset info for ' . $uuid);
$this->logger()->error('Unable to find dataset info for ' . $uuid);
}
}

Expand All @@ -102,10 +95,10 @@ protected function reimportDistributions(array $distributions) {
foreach ($distributions as $distribution) {
if ($resource_id = $distribution['resource_id'] ?? FALSE) {
$this->datastoreService->drop($resource_id);
$this->loggerFactory->get('datastore')->notice('Reimporting distribution: ' . $resource_id);
$this->logger()->notice('Reimporting distribution: ' . $resource_id);
$result = $this->datastoreService->import($resource_id);
$status = $result['ImportService'] ? $result['ImportService']->getStatus() : 'failed, resource not found';
$this->loggerFactory->get('datastore')->notice("Ran import for $resource_id; status: $status");
$this->logger()->notice("Ran import for $resource_id; status: $status");
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions modules/datastore/src/EventSubscriber/DatastoreSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Drupal\datastore\EventSubscriber;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Logger\LoggerChannelFactory;
use Drupal\common\DataResource;
use Drupal\common\Events\Event;
use Drupal\datastore\DatastoreService;
Expand All @@ -13,6 +12,7 @@
use Drupal\metastore\LifeCycle\LifeCycle;
use Drupal\metastore\MetastoreItemInterface;
use Drupal\metastore\ResourceMapper;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

Expand All @@ -29,11 +29,11 @@ class DatastoreSubscriber implements EventSubscriberInterface {
protected $configFactory;

/**
* Logger service.
* Datastore logger channel service.
*
* @var \Drupal\Core\Logger\LoggerChannelFactory
* @var \Psr\Log\LoggerInterface
*/
protected $loggerFactory;
protected LoggerInterface $logger;

/**
* Datastore service.
Expand Down Expand Up @@ -64,7 +64,7 @@ class DatastoreSubscriber implements EventSubscriberInterface {
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('logger.factory'),
$container->get('dkan.datastore.logger_channel'),
$container->get('dkan.datastore.service'),
$container->get('dkan.datastore.service.resource_purger'),
$container->get('dkan.datastore.import_job_store_factory')
Expand All @@ -76,8 +76,8 @@ public static function create(ContainerInterface $container) {
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* A ConfigFactory service instance.
* @param \Drupal\Core\Logger\LoggerChannelFactory $logger_factory
* LoggerChannelFactory service.
* @param \Psr\Log\LoggerInterface $loggerChannel
* Logger channel.
* @param \Drupal\datastore\DatastoreService $service
* The dkan.datastore.service service.
* @param \Drupal\datastore\Service\ResourcePurger $resourcePurger
Expand All @@ -87,13 +87,13 @@ public static function create(ContainerInterface $container) {
*/
public function __construct(
ConfigFactoryInterface $config_factory,
LoggerChannelFactory $logger_factory,
LoggerInterface $loggerChannel,
DatastoreService $service,
ResourcePurger $resourcePurger,
ImportJobStoreFactory $importJobStoreFactory
) {
$this->configFactory = $config_factory;
$this->loggerFactory = $logger_factory;
$this->logger = $loggerChannel;
$this->datastoreService = $service;
$this->resourcePurger = $resourcePurger;
$this->importJobStoreFactory = $importJobStoreFactory;
Expand Down Expand Up @@ -131,7 +131,7 @@ public function onRegistration(Event $event) {
$this->datastoreService->import($resource->getIdentifier(), TRUE, $resource->getVersion());
}
catch (\Exception $e) {
$this->loggerFactory->get('datastore')->error($e->getMessage());
$this->logger->error($e->getMessage());
}
}
}
Expand Down Expand Up @@ -168,10 +168,10 @@ public function drop(Event $event) {
$id = md5(str_replace(DataResource::DEFAULT_SOURCE_PERSPECTIVE, ResourceLocalizer::LOCAL_FILE_PERSPECTIVE, $resource->getUniqueIdentifier()));
try {
$this->datastoreService->drop($resource->getIdentifier(), $resource->getVersion());
$this->loggerFactory->get('datastore')->notice('Dropping datastore for @id', ['@id' => $id]);
$this->logger->notice('Dropping datastore for @id', ['@id' => $id]);
}
catch (\Exception $e) {
$this->loggerFactory->get('datastore')->error('Failed to drop datastore for @id. @message',
$this->logger->error('Failed to drop datastore for @id. @message',
[
'@id' => $id,
'@message' => $e->getMessage(),
Expand All @@ -181,7 +181,7 @@ public function drop(Event $event) {
$this->importJobStoreFactory->getInstance()->remove($id);
}
catch (\Exception $e) {
$this->loggerFactory->get('datastore')->error('Failed to remove importer job. @message',
$this->logger->error('Failed to remove importer job. @message',
[
'@message' => $e->getMessage(),
]);
Expand Down
17 changes: 7 additions & 10 deletions modules/datastore/src/Plugin/QueueWorker/ImportQueueWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
namespace Drupal\datastore\Plugin\QueueWorker;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;

use Drupal\common\Storage\DatabaseConnectionFactoryInterface;
use Drupal\common\Storage\ImportedItemInterface;
use Drupal\datastore\DatastoreService;
use Drupal\metastore\Reference\ReferenceLookup;

use Procrastinator\Result;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand Down Expand Up @@ -68,9 +65,9 @@ class ImportQueueWorker extends QueueWorkerBase implements ContainerFactoryPlugi
/**
* Logger service.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
* @var \Psr\Log\LoggerInterface
*/
protected LoggerChannelInterface $logger;
protected LoggerInterface $logger;

/**
* Constructs a \Drupal\Component\Plugin\PluginBase object.
Expand All @@ -85,7 +82,7 @@ class ImportQueueWorker extends QueueWorkerBase implements ContainerFactoryPlugi
* A config factory instance.
* @param \Drupal\datastore\DatastoreService $datastore
* A DKAN datastore service instance.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerFactory
* @param \Psr\Log\LoggerInterface $loggerChannel
* A logger channel factory instance.
* @param \Drupal\metastore\Reference\ReferenceLookup $referenceLookup
* The reference lookup service.
Expand All @@ -100,7 +97,7 @@ public function __construct(
$plugin_definition,
ConfigFactoryInterface $configFactory,
DatastoreService $datastore,
LoggerChannelFactoryInterface $loggerFactory,
LoggerInterface $loggerChannel,
ReferenceLookup $referenceLookup,
DatabaseConnectionFactoryInterface $defaultConnectionFactory,
DatabaseConnectionFactoryInterface $datastoreConnectionFactory
Expand All @@ -111,7 +108,7 @@ public function __construct(
$this->datastoreConfig = $configFactory->get('datastore.settings');
$this->databaseQueue = $datastore->getQueueFactory()->get($plugin_id);
$this->fileSystem = $datastore->getResourceLocalizer()->getFileSystem();
$this->logger = $loggerFactory->get('datastore');
$this->logger = $loggerChannel;
// Set the timeout for database connections to the queue lease time.
// This ensures that database connections will remain open for the
// duration of the time the queue is being processed.
Expand All @@ -130,7 +127,7 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_definition,
$container->get('config.factory'),
$container->get('dkan.datastore.service'),
$container->get('logger.factory'),
$container->get('dkan.datastore.logger_channel'),
$container->get('dkan.metastore.reference_lookup'),
$container->get('dkan.common.database_connection_factory'),
$container->get('dkan.datastore.database_connection_factory')
Expand Down
15 changes: 7 additions & 8 deletions modules/datastore/src/Plugin/QueueWorker/LocalizeQueueWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

namespace Drupal\datastore\Plugin\QueueWorker;

use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\datastore\Service\ResourceLocalizer;
use Procrastinator\Result;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand All @@ -34,9 +33,9 @@ class LocalizeQueueWorker extends QueueWorkerBase implements ContainerFactoryPlu
/**
* Logger service.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
* @var \Psr\Log\LoggerInterface
*/
protected LoggerChannelInterface $logger;
protected LoggerInterface $logger;

/**
* Constructs a \Drupal\Component\Plugin\PluginBase object.
Expand All @@ -50,19 +49,19 @@ class LocalizeQueueWorker extends QueueWorkerBase implements ContainerFactoryPlu
* A DKAN datastore service instance.
* @param \Drupal\datastore\Service\ResourceLocalizer $resourceLocalizer
* Resource localizer service.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerFactory
* @param \Psr\Log\LoggerInterface $loggerChannel
* A logger channel factory instance.
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
ResourceLocalizer $resourceLocalizer,
LoggerChannelFactoryInterface $loggerFactory
LoggerInterface $loggerChannel
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->resourceLocalizer = $resourceLocalizer;
$this->logger = $loggerFactory->get('datastore');
$this->logger = $loggerChannel;
}

/**
Expand All @@ -74,7 +73,7 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_id,
$plugin_definition,
$container->get('dkan.datastore.service.resource_localizer'),
$container->get('logger.factory')
$container->get('dkan.datastore.logger_channel')
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@

namespace Drupal\datastore\Plugin\QueueWorker;

use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;

use Drupal\common\DataResource;
use Drupal\datastore\DataDictionary\AlterTableQueryBuilderInterface;
use Drupal\datastore\Service\ResourceProcessorCollector;
use Drupal\metastore\ResourceMapper;
use Drupal\datastore\PostImportResult;
use Drupal\metastore\Reference\ReferenceLookup;
use Drupal\datastore\Service\PostImport;
use Drupal\datastore\Service\ResourceProcessorCollector;
use Drupal\metastore\DataDictionary\DataDictionaryDiscoveryInterface;

use Drupal\metastore\Reference\ReferenceLookup;
use Drupal\metastore\ResourceMapper;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand All @@ -35,9 +32,9 @@ class PostImportResourceProcessor extends QueueWorkerBase implements ContainerFa
/**
* A logger channel for this plugin.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
* @var \Psr\Log\LoggerInterface
*/
protected LoggerChannelInterface $logger;
protected LoggerInterface $logger;

/**
* The metastore resource mapper service.
Expand Down Expand Up @@ -85,7 +82,7 @@ class PostImportResourceProcessor extends QueueWorkerBase implements ContainerFa
* The plugin implementation definition.
* @param \Drupal\datastore\DataDictionary\AlterTableQueryBuilderInterface $alter_table_query_builder
* The alter table query factory service.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory
* @param \Psr\Log\LoggerInterface $logger_channel
* A logger channel factory instance.
* @param \Drupal\metastore\ResourceMapper $resource_mapper
* The metastore resource mapper service.
Expand All @@ -103,15 +100,15 @@ public function __construct(
$plugin_id,
$plugin_definition,
AlterTableQueryBuilderInterface $alter_table_query_builder,
LoggerChannelFactoryInterface $logger_factory,
LoggerInterface $logger_channel,
ResourceMapper $resource_mapper,
ResourceProcessorCollector $processor_collector,
PostImport $post_import,
DataDictionaryDiscoveryInterface $data_dictionary_discovery,
ReferenceLookup $referenceLookup
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->logger = $logger_factory->get('datastore');
$this->logger = $logger_channel;
$this->resourceMapper = $resource_mapper;
$this->resourceProcessorCollector = $processor_collector;
$this->postImport = $post_import;
Expand All @@ -133,7 +130,7 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_id,
$plugin_definition,
$container->get('dkan.datastore.data_dictionary.alter_table_query_builder.mysql'),
$container->get('logger.factory'),
$container->get('dkan.datastore.logger_channel'),
$container->get('dkan.metastore.resource_mapper'),
$container->get('dkan.datastore.service.resource_processor_collector'),
$container->get('dkan.datastore.service.post_import'),
Expand Down
Loading

0 comments on commit 6c42374

Please sign in to comment.