diff --git a/dgi_fixity.services.yml b/dgi_fixity.services.yml index ae9da2e..94f42b5 100644 --- a/dgi_fixity.services.yml +++ b/dgi_fixity.services.yml @@ -1,11 +1,9 @@ services: - logger.channel.dgi_fixity: - class: Drupal\Core\Logger\LoggerChannel - factory: logger.factory:get - arguments: ['dgi_fixity'] dgi_fixity.fixity_check: class: Drupal\dgi_fixity\FixityCheckService - arguments: ['@string_translation', '@config.factory', '@entity_type.manager', '@datetime.time', '@plugin.manager.mail', '@logger.channel.dgi_fixity', '@filehash'] + arguments: ['@string_translation', '@config.factory', '@entity_type.manager', '@datetime.time', '@filehash'] + calls: + - [setLoggerFactory, ['@logger.factory']] dgi_fixity.route_subscriber: class: Drupal\dgi_fixity\Routing\FixityCheckRouteSubscriber arguments: ['@entity_type.manager', '@dgi_fixity.fixity_check'] @@ -16,3 +14,7 @@ services: arguments: ['@entity_type.manager', '@entity.repository', '@dgi_fixity.fixity_check'] tags: - { name: paramconverter } + logger.channel.dgi_fixity: + class: Drupal\Core\Logger\LoggerChannel + factory: logger.factory:get + arguments: ['dgi_fixity'] diff --git a/src/FixityCheckService.php b/src/FixityCheckService.php index ecdcee1..e6cc552 100644 --- a/src/FixityCheckService.php +++ b/src/FixityCheckService.php @@ -7,7 +7,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Link; -use Drupal\Core\Mail\MailManagerInterface; +use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\dgi_fixity\Entity\FixityCheck; @@ -18,7 +18,6 @@ use Drupal\filehash\FileHash; use Drupal\media\MediaInterface; use Drupal\views\ViewExecutable; use Drupal\views\Views; -use Psr\Log\LoggerInterface; /** * Decorates the FileHash services adding additional functionality. @@ -48,17 +47,10 @@ class FixityCheckService implements FixityCheckServiceInterface { */ protected $time; - /** - * The mail manager service. - * - * @var \Drupal\Core\Mail\MailManagerInterface - */ - protected $mailManager; - /** * The logger for this service. * - * @var Psr\Log\LoggerInterface + * @var \Psr\Log\LoggerInterface */ protected $logger; @@ -69,19 +61,53 @@ class FixityCheckService implements FixityCheckServiceInterface { */ protected $filehash; + /** + * The logger factory. + * + * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface + */ + protected LoggerChannelFactoryInterface $loggerFactory; + /** * Constructor. */ - public function __construct(TranslationInterface $string_translation, ConfigFactoryInterface $config, EntityTypeManagerInterface $entity_type_manager, TimeInterface $time, MailManagerInterface $mail_manager, LoggerInterface $logger, FileHash $filehash) { + public function __construct( + TranslationInterface $string_translation, + ConfigFactoryInterface $config, + EntityTypeManagerInterface $entity_type_manager, + TimeInterface $time, + FileHash $filehash + ) { $this->stringTranslation = $string_translation; $this->config = $config; $this->entityTypeManager = $entity_type_manager; $this->time = $time; - $this->mailManager = $mail_manager; - $this->logger = $logger; $this->filehash = $filehash; } + /** + * Sets the logger factory. + * + * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerFactory + * The logger factory. + */ + public function setLoggerFactory(LoggerChannelFactoryInterface $loggerFactory) { + $this->loggerFactory = $loggerFactory; + } + + /** + * Gets the logger channel. + * + * @return \Psr\Log\LoggerInterface + * The logger channel. + */ + protected function getLogger() { + if (!isset($this->logger)) { + $this->logger = $this->loggerFactory->get('dgi_fixity'); + } + return $this->logger; + } + /** * {@inheritdoc} */ @@ -272,10 +298,10 @@ class FixityCheckService implements FixityCheckServiceInterface { )->toString(), ]; if ($check->passed()) { - $this->logger->info($message, $args); + $this->getLogger()->info($message, $args); } else { - $this->logger->error($message, $args); + $this->getLogger()->error($message, $args); } return $check;