diff --git a/composer.json b/composer.json index 5045ddaf76e57be7e8fc14adaf5c1e1ae2f3ab8e..cb744de2fa3b939f7b15a84a25fafc1a7ff72eff 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, "require": { "drupal/monitoring": "^1.12", - "php": "^8.1", - "drupal/core": "^9.4 || ^10" + "php": "^8.1 || ^8.3", + "drupal/core": "^9.4 || ^10 || ^11" } } diff --git a/modules/monitoring_logging_check_drupal/monitoring_logging_check_drupal.info.yml b/modules/monitoring_logging_check_drupal/monitoring_logging_check_drupal.info.yml index 7c4c0b15ab0928825e08fa22fcbc67f637159faa..9adeafaaf6982b54ac8cac006d4fc967d9290a76 100644 --- a/modules/monitoring_logging_check_drupal/monitoring_logging_check_drupal.info.yml +++ b/modules/monitoring_logging_check_drupal/monitoring_logging_check_drupal.info.yml @@ -1,7 +1,7 @@ name: Monitoring Logging check_drupal type: module description: Provides a monitoring file logger formatter that outputs the log in a file, in a format readable by https://github.com/cytopia/check_drupal. -core_version_requirement: ^9.4 || ^10 +core_version_requirement: ^9.4 || ^10 || ^11 package: Monitoring dependencies: - monitoring_logging:monitoring_logging diff --git a/monitoring_logging.info.yml b/monitoring_logging.info.yml index 3bb5b7270d3bda7e5bfdac8d5d78b00fdf8c7285..0ebfa68a6d7d479e271df5385107dec83d5385a7 100644 --- a/monitoring_logging.info.yml +++ b/monitoring_logging.info.yml @@ -1,7 +1,7 @@ name: Monitoring Logging type: module description: Outputs an overview of sensor results to a log. -core_version_requirement: ^9.4 || ^10 +core_version_requirement: ^9.4 || ^10 || ^11 package: Monitoring dependencies: - monitoring:monitoring diff --git a/src/Plugin/Logger/File.php b/src/Plugin/Logger/File.php index 022e30bb183e3a9802eb9a2ca39d39c89689b3c3..428e63b3d927d47f7d76f167996b6d1c693a2166 100644 --- a/src/Plugin/Logger/File.php +++ b/src/Plugin/Logger/File.php @@ -6,14 +6,17 @@ use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Core\File\Exception\FileException; +use Drupal\Core\File\FileExists; use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginDependencyTrait; use Drupal\Core\Plugin\PluginWithFormsInterface; +use Drupal\Core\Utility\Error; use Drupal\monitoring\Result\SensorResultInterface; use Drupal\monitoring_logging\FileLogFormatterManager; use Drupal\monitoring_logging\Form\LoggerFileForm; use Drupal\monitoring_logging\LoggerBase; +use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -42,6 +45,13 @@ class File extends LoggerBase implements PluginWithFormsInterface, ConfigurableI */ protected $fileSystem; + /** + * The logger service. + * + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + /** * Creates a file logger. * @@ -55,17 +65,21 @@ class File extends LoggerBase implements PluginWithFormsInterface, ConfigurableI * The file log formatter plugin manager. * @param \Drupal\Core\File\FileSystemInterface $fileSystem * The file system implementation. + * @param \Psr\Log\LoggerInterface $logger + * The logger service. */ public function __construct( array $configuration, $plugin_id, $plugin_definition, FileLogFormatterManager $fileLogFormatterManager, - FileSystemInterface $fileSystem + FileSystemInterface $fileSystem, + LoggerInterface $logger, ) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->fileLogFormatterManager = $fileLogFormatterManager; $this->fileSystem = $fileSystem; + $this->logger = $logger; } /** @@ -77,7 +91,8 @@ class File extends LoggerBase implements PluginWithFormsInterface, ConfigurableI $plugin_id, $plugin_definition, $container->get('plugin.manager.monitoring_file_log_formatter'), - $container->get('file_system') + $container->get('file_system'), + $container->get('logger.factory')->get('default') ); } @@ -86,10 +101,10 @@ class File extends LoggerBase implements PluginWithFormsInterface, ConfigurableI */ public function logResults(SensorResultInterface ...$results) { try { - return $this->fileSystem->saveData($this->getFormatter()->format(...$results), $this->getFile(), FileSystemInterface::EXISTS_REPLACE); + return $this->fileSystem->saveData($this->getFormatter()->format(...$results), $this->getFile(), FileExists::Replace); } catch (FileException $e) { - watchdog_exception('monitoring_logging', $e); + Error::logException($this->logger, $e); } return FALSE; } @@ -144,7 +159,7 @@ class File extends LoggerBase implements PluginWithFormsInterface, ConfigurableI return $this->fileLogFormatterManager->createInstance($this->getConfiguration()['formatter']); } catch (PluginNotFoundException $ex) { - watchdog_exception('monitoring_logging', $ex); + Error::logException($this->logger, $ex); } } return FALSE; diff --git a/tests/src/Unit/Plugin/Logger/FileTest.php b/tests/src/Unit/Plugin/Logger/FileTest.php index d563a87f9fd5565e9837b31ce9afe020f98be702..f6fa4c26fb62d3860f58dab100f0f056145f9a4a 100644 --- a/tests/src/Unit/Plugin/Logger/FileTest.php +++ b/tests/src/Unit/Plugin/Logger/FileTest.php @@ -6,6 +6,7 @@ use Prophecy\PhpUnit\ProphecyTrait; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ThemeHandlerInterface; use Drupal\Core\File\FileSystemInterface; +use Drupal\Core\File\FileExists; use Drupal\monitoring\Result\SensorResultInterface; use Drupal\monitoring_logging\FileLogFormatterInterface; use Drupal\monitoring_logging\FileLogFormatterManager; @@ -68,7 +69,7 @@ final class FileTest extends UnitTestCase { $this->formatter->format(...$results)->willReturn($formattedText); $this->fileSystem - ->saveData($formattedText, $destination, FileSystemInterface::EXISTS_REPLACE) + ->saveData($formattedText, $destination, FileExists::Replace) ->shouldBeCalled() ->willReturn($destination); $logger = $this->getLogger([