From 3df5a7ef4162f031c84a6185c8bc868bfe482414 Mon Sep 17 00:00:00 2001 From: Mohamed EL QUCHIRI <88336621+melquchiri-tbd@users.noreply.github.com> Date: Mon, 24 Feb 2025 14:19:59 +0100 Subject: [PATCH 1/3] Update composer.json to upgrade monolog version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 93fbf99b..56c01c44 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "require": { "symfony/console": "^6.4", "magento/framework": "*", - "monolog/monolog": "^2.3" + "monolog/monolog": "^3.6" }, "require-dev": { "phpunit/phpunit": "~9.5.0" From 77e4390e17be3520bf5c49120cff65d0b5444db7 Mon Sep 17 00:00:00 2001 From: Mohamed Date: Mon, 24 Feb 2025 16:20:32 +0100 Subject: [PATCH 2/3] Adapt module with new version of monolog --- src/Migration/Logger/ConsoleHandler.php | 3 ++- src/Migration/Logger/FileHandler.php | 3 ++- src/Migration/Logger/Logger.php | 6 ++++-- src/Migration/Logger/MessageFormatter.php | 6 ++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Migration/Logger/ConsoleHandler.php b/src/Migration/Logger/ConsoleHandler.php index c59aeca1..7ad915c7 100644 --- a/src/Migration/Logger/ConsoleHandler.php +++ b/src/Migration/Logger/ConsoleHandler.php @@ -10,6 +10,7 @@ use Monolog\Handler\HandlerInterface; use Monolog\Handler\AbstractHandler; use Psr\Log\LogLevel; +use Monolog\LogRecord; /** * Processing logger handler creation for migration application @@ -46,7 +47,7 @@ protected function colorize($string, $color) /** * @inheritdoc */ - public function handle(array $record): bool + public function handle(LogRecord $record): bool { if (!$this->isHandling($record)) { return false; diff --git a/src/Migration/Logger/FileHandler.php b/src/Migration/Logger/FileHandler.php index 8af386e1..fb0f9663 100644 --- a/src/Migration/Logger/FileHandler.php +++ b/src/Migration/Logger/FileHandler.php @@ -10,6 +10,7 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Monolog\Formatter\FormatterInterface; use Monolog\Handler\HandlerInterface; +use Monolog\LogRecord; /** * Processing logger handler creation for migration application @@ -59,7 +60,7 @@ public function __construct(File $file, Config $config, \Magento\Framework\Files /** * @inheritdoc */ - public function handle(array $record): bool + public function handle(LogRecord $record): bool { if (!$this->isHandling($record)) { return false; diff --git a/src/Migration/Logger/Logger.php b/src/Migration/Logger/Logger.php index d933bb59..3b906892 100644 --- a/src/Migration/Logger/Logger.php +++ b/src/Migration/Logger/Logger.php @@ -6,7 +6,8 @@ namespace Migration\Logger; -use Monolog\DateTimeImmutable; +use Monolog\JsonSerializableDateTimeImmutable; +use Monolog\Level; /** * Processing logger handler creation for migration application @@ -33,7 +34,8 @@ public function __construct($name = 'Migration', array $handlers = [], array $pr /** * @inheritdoc */ - public function addRecord(int $level, string $message, array $context = [], DateTimeImmutable $datetime = null): bool + + public function addRecord(int|Level $level, string $message, array $context = [], JsonSerializableDateTimeImmutable|null $datetime = null): bool { $processed = parent::addRecord($level, $message, $context); self::$messages[$level][] = $message; diff --git a/src/Migration/Logger/MessageFormatter.php b/src/Migration/Logger/MessageFormatter.php index 51b734c7..c998c51e 100644 --- a/src/Migration/Logger/MessageFormatter.php +++ b/src/Migration/Logger/MessageFormatter.php @@ -5,6 +5,8 @@ */ namespace Migration\Logger; +use Monolog\LogRecord; + /** * Format logger messages corresponding to verbosity level */ @@ -13,12 +15,12 @@ class MessageFormatter extends \Monolog\Formatter\LineFormatter implements \Mono /** * @inheritdoc */ - protected $format; + protected string $format; /** * @inheritdoc */ - public function format(array $record): string + public function format(LogRecord $record): string { $this->format = $this->getLevelFormat($record['level_name']); return parent::format($record); From 04b6c1f3726c4af34892d5d0ee576d96133c561f Mon Sep 17 00:00:00 2001 From: Mohamed Date: Fri, 28 Feb 2025 15:36:12 +0100 Subject: [PATCH 3/3] Fix Logger and MessageProcessor --- src/Migration/Logger/Logger.php | 5 +++-- src/Migration/Logger/MessageProcessor.php | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Migration/Logger/Logger.php b/src/Migration/Logger/Logger.php index 3b906892..c5921e40 100644 --- a/src/Migration/Logger/Logger.php +++ b/src/Migration/Logger/Logger.php @@ -37,8 +37,9 @@ public function __construct($name = 'Migration', array $handlers = [], array $pr public function addRecord(int|Level $level, string $message, array $context = [], JsonSerializableDateTimeImmutable|null $datetime = null): bool { - $processed = parent::addRecord($level, $message, $context); - self::$messages[$level][] = $message; + $levelValue = $level instanceof Level ? $level->value : $level; + $processed = parent::addRecord($levelValue, $message, $context); + self::$messages[$levelValue][] = $message; return $processed; } diff --git a/src/Migration/Logger/MessageProcessor.php b/src/Migration/Logger/MessageProcessor.php index 7f66ce39..bfb91c73 100644 --- a/src/Migration/Logger/MessageProcessor.php +++ b/src/Migration/Logger/MessageProcessor.php @@ -5,6 +5,8 @@ */ namespace Migration\Logger; +use Monolog\LogRecord; + /** * Logger messages processor */ @@ -23,10 +25,10 @@ class MessageProcessor /** * Set extra * - * @param array $record + * @param LogRecord $record * @return array */ - public function setExtra(array $record) + public function setExtra(LogRecord $record) { foreach ($record['context'] as $key => $value) { switch ($key) {